On 04/30/2015 04:11 AM, Alberto Garcia wrote: > Since all tables are now stored together, it is possible to obtain > the position of a particular table directly from its address, so the > operation becomes O(1). > > Signed-off-by: Alberto Garcia <be...@igalia.com> > --- > block/qcow2-cache.c | 22 +++++----------------- > 1 file changed, 5 insertions(+), 17 deletions(-) > > diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c > index 586880b..d3274f4 100644 > --- a/block/qcow2-cache.c > +++ b/block/qcow2-cache.c > @@ -335,16 +335,12 @@ int qcow2_cache_get_empty(BlockDriverState *bs, > Qcow2Cache *c, uint64_t offset, > > int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table) > { > - int i; > + int i = (*table - c->table_array) / c->table_size;
Arithmetic on void* is not portable. > void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table) > { > - int i; > - > - for (i = 0; i < c->size; i++) { > - if (table_addr(c, i) == table) { > - goto found; > - } > - } > - abort(); > - > -found: > + int i = (table - c->table_array) / c->table_size; and again. > + assert(c->entries[i].offset != 0); > c->entries[i].dirty = true; > } > -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature