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

[libvirt] [PATCHv4 11/51] 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.
---
 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 00212db..993d590 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11215,23 +11215,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]