Commit 1b826f27 authored by ChenLiang's avatar ChenLiang Committed by Amit Shah
Browse files

xbzrle: rebuild the cache_is_cached function



Rebuild the cache_is_cached function by cache_get_by_addr. And
drops the asserts because the caller is also asserting the same
thing.

Signed-off-by: default avatarChenLiang <chenliang88@huawei.com>
Signed-off-by: default avatarGonglei <arei.gonglei@huawei.com>
Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
parent 27af7d6e
Loading
Loading
Loading
Loading
+16 −22
Original line number Diff line number Diff line
@@ -125,24 +125,6 @@ static size_t cache_get_cache_pos(const PageCache *cache,
    return pos;
}

bool cache_is_cached(const PageCache *cache, uint64_t addr,
                     uint64_t current_age)
{
    size_t pos;

    g_assert(cache);
    g_assert(cache->page_cache);

    pos = cache_get_cache_pos(cache, addr);

    if (cache->page_cache[pos].it_addr == addr) {
        /* update the it_age when the cache hit */
        cache->page_cache[pos].it_age = current_age;
        return true;
    }
    return false;
}

static CacheItem *cache_get_by_addr(const PageCache *cache, uint64_t addr)
{
    size_t pos;
@@ -160,14 +142,26 @@ uint8_t *get_cached_data(const PageCache *cache, uint64_t addr)
    return cache_get_by_addr(cache, addr)->it_data;
}

int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
bool cache_is_cached(const PageCache *cache, uint64_t addr,
                     uint64_t current_age)
{
    CacheItem *it;

    CacheItem *it = NULL;
    it = cache_get_by_addr(cache, addr);

    g_assert(cache);
    g_assert(cache->page_cache);
    if (it->it_addr == addr) {
        /* update the it_age when the cache hit */
        it->it_age = current_age;
        return true;
    }
    return false;
}

int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
                 uint64_t current_age)
{

    CacheItem *it;

    /* actual update of entry */
    it = cache_get_by_addr(cache, addr);