From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpegL-0004NV-Ep for qemu-devel@nongnu.org; Tue, 05 May 2015 11:22:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpegH-00065W-C5 for qemu-devel@nongnu.org; Tue, 05 May 2015 11:22:49 -0400 Message-ID: <5548E016.4020208@redhat.com> Date: Tue, 05 May 2015 09:21:58 -0600 From: Eric Blake MIME-Version: 1.0 References: <65c04848cf88f3342e229464e72d1124ce3d8de9.1430388393.git.berto@igalia.com> In-Reply-To: <65c04848cf88f3342e229464e72d1124ce3d8de9.1430388393.git.berto@igalia.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Hep18jiUTDJ5PRX7Mf9phjdFghjeWbtSe" Subject: Re: [Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Hep18jiUTDJ5PRX7Mf9phjdFghjeWbtSe Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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). >=20 > Signed-off-by: Alberto Garcia > --- > block/qcow2-cache.c | 22 +++++----------------- > 1 file changed, 5 insertions(+), 17 deletions(-) >=20 > 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, Q= cow2Cache *c, uint64_t offset, > =20 > int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table)= > { > - int i; > + int i =3D (*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 =3D 0; i < c->size; i++) { > - if (table_addr(c, i) =3D=3D table) { > - goto found; > - } > - } > - abort(); > - > -found: > + int i =3D (table - c->table_array) / c->table_size; and again. > + assert(c->entries[i].offset !=3D 0); > c->entries[i].dirty =3D true; > } >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Hep18jiUTDJ5PRX7Mf9phjdFghjeWbtSe Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVSOAWAAoJEKeha0olJ0NqyRsH/RkOihVQ2jNA8jPFbJcjLtOj IDJ0cUcuTNCzxi11RcUhEbK0Sy/0l7U/UqauYxpyfKrJX6NHK0b5lfKZQPcqWh1t UwWUScBLmq3eLdkIqTwYM7Is6Zc4GMV3Chz5Ix9SSpS2kyYRYwsH2V9QJop3URH/ JhKtsvwnWtnITUm6rBUYtSA87nz/SPSAzhozaSr9DaB09Thigv8WwN4NfIWKqOsL 3aB+8ipzqp8UILKRhaSSiuYITKc5ZoGAARt355ZI6E8U3/mFmhqWDFNAEG60uHSE a1CuSsELmVTc4jMi17qZg6zBS3hC1QYavs3FIiLDXaPS3DAa2GknMUMoikyIo98= =6SDA -----END PGP SIGNATURE----- --Hep18jiUTDJ5PRX7Mf9phjdFghjeWbtSe--