From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlyOk-0001bh-9t for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:09:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlyOg-00032n-Uk for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:09:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlyOg-00032U-PX for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:09:38 -0400 Date: Tue, 13 Oct 2015 13:09:32 +0100 From: "Daniel P. Berrange" Message-ID: <20151013120932.GH18659@redhat.com> References: <1444313344-16196-1-git-send-email-berrange@redhat.com> <1444313344-16196-2-git-send-email-berrange@redhat.com> <561699D7.1010105@redhat.com> <87pp0ozbmp.fsf_-_@blackfin.pond.sub.org> <20151012100004.GH21855@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20151012100004.GH21855@redhat.com> Subject: Re: [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Pavel Fedin , qemu-devel@nongnu.org, Andreas =?utf-8?Q?F=C3=A4rber?= On Mon, Oct 12, 2015 at 11:00:04AM +0100, Daniel P. Berrange wrote: > On Fri, Oct 09, 2015 at 10:31:26AM +0200, Markus Armbruster wrote: > > We have quite a few _foreach-functions to help iterate over various > > things. They are easy enough to write, but I find them awkward to use. > > > > Implementing bdrv_next() is no harder than bdrv_iterate(). Compare: > > > > BlockDriverState *bdrv_next(BlockDriverState *bs) > > { > > if (!bs) { > > return QTAILQ_FIRST(&bdrv_states); > > } > > return QTAILQ_NEXT(bs, device_list); > > } > > > > void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque) > > { > > BlockDriverState *bs; > > > > QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > > it(opaque, bs); > > } > > } > > I don't think your example here is a reasonable comparison when you consider > the full extent of this patch series. You are only having to iterate over a > single data structure here. At the end of this patch series we have to > iterate over multiple data structures spread across the object instance > and class hierarchy, so writing a 'next' like method is not as trivial > as you suggest with this comparison. So it turns out I was wrong here. After a little more thinking I found it was in fact fairly trivial to support a "next" like iterator in this QOM property scenario, even when taking class properties into account. So I'll re-spin this patch series with that approach, since it makes the diffs much smaller Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|