]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: Refactor virHashForEach so it returns as soon as an iterator fails
authorErik Skultety <eskultet@redhat.com>
Fri, 12 Feb 2016 09:15:57 +0000 (10:15 +0100)
committerErik Skultety <eskultet@redhat.com>
Wed, 17 Feb 2016 11:46:34 +0000 (12:46 +0100)
commit353de572a6d5167e337bee4151e250f47bb3ae90
treeb4f5f4d0e8301bf47a88748feef20b00d8e8cd7c
parentcc48d3a12244a2bd7fc09512a83afbb57e4cb153
util: Refactor virHashForEach so it returns as soon as an iterator fails

The method will now return 0 on success and -1 on error, rather than number of
items which it iterated over before it returned back to the caller. Since the
only place where we actually check the number of elements iterated is in
virhashtest, return value of 0 and -1 can be a pretty accurate hint that it
iterated over all the items. However, if we really want to know the number of
items iterated over (like virhashtest does), a counter has to be provided
through opaque data to each iterator call. This patch adjusts return value of
virHashForEach, refactors the body, so it returns as soon as one of the
iterators fail and adjusts virhashtest to reflect these changes.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/util/virhash.c
src/util/virhash.h
tests/virhashtest.c