Add a string equality check function to string pool API
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 05:48:56 +0000 (08:48 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 06:01:30 +0000 (09:01 +0300)
- As a special case, two strings (ids) from the same pool can be tested for
  equality in constant time (integer comparison). If the pools differ,
  a regular string comparison is needed.

rpmio/rpmstrpool.c
rpmio/rpmstrpool.h

index 55fc0e0..799136b 100644 (file)
@@ -173,3 +173,12 @@ size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid)
     }
     return slen;
 }
+
+int rpmstrPoolStreq(rpmstrPool poolA, rpmsid sidA,
+                   rpmstrPool poolB, rpmsid sidB)
+{
+    if (poolA == poolB)
+       return (sidA == sidB);
+    else
+       return rstreq(rpmstrPoolStr(poolA, sidA), rpmstrPoolStr(poolB, sidB));
+}
index 67e1620..5794032 100644 (file)
@@ -36,6 +36,10 @@ const char * rpmstrPoolStr(rpmstrPool sidpool, rpmsid sid);
 /* get a strings length by its id (in constant time) */
 size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid);
 
+/* pool string equality comparison (constant time if within same pool) */
+int rpmstrPoolStreq(rpmstrPool poolA, rpmsid sidA,
+                    rpmstrPool poolB, rpmsid sidB);
+
 #ifdef __cplusplus
 }
 #endif