[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv3 07.9/43] snapshot: speed up snapshot location



Each snapshot lookup was iterating over the entire hash table, O(n),
instead of honing in directly on the hash key, amortized O(1).

Besides, fixing this means that virDomainSnapshotFindByName can now
be used inside another virHashForeach iteration (without this patch,
attempts to lookup a snapshot by name during a hash iteration will
fail due to nested iteration).

* src/conf/domain_conf.c (virDomainSnapshotFindByName): Simplify.
(virDomainSnapshotObjListSearchName): Delete unused function.
---

This patch is necessary prior to patch 8/43 to fix the recursive
iteration bug reported by Dan.  The actual patch 8/43 does not have
to change!

 src/conf/domain_conf.c |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 44212cf..6f19b6c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11213,23 +11213,11 @@ int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots)
     return count;
 }

-static int virDomainSnapshotObjListSearchName(const void *payload,
-                                              const void *name ATTRIBUTE_UNUSED,
-                                              const void *data)
-{
-    virDomainSnapshotObjPtr obj = (virDomainSnapshotObjPtr)payload;
-    int want = 0;
-
-    if (STREQ(obj->def->name, (const char *)data))
-        want = 1;
-
-    return want;
-}
-
-virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
-                                                    const char *name)
+virDomainSnapshotObjPtr
+virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
+                            const char *name)
 {
-    return virHashSearch(snapshots->objs, virDomainSnapshotObjListSearchName, name);
+    return virHashLookup(snapshots->objs, name);
 }

 void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]