Split actual cursor get + set-conversion to separate function
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Jun 2011 15:46:45 +0000 (18:46 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Jun 2011 15:46:45 +0000 (18:46 +0300)
- Allows multiple retrieves on a single cursor instance, dbiGetToSet()
  is just a convenience wrapper around dbiCursorGetToSet() now.
- Creating and tearing down cursors isn't exactly terrifyingly
  expensive but still measurable when lots of lookups are done.

lib/rpmdb.c

index ce481be..4f831bb 100644 (file)
@@ -445,22 +445,16 @@ static dbiIndexSet dbiIndexSetFree(dbiIndexSet set)
     return NULL;
 }
 
-static int dbiGetToSet(dbiIndex dbi, const char *keyp, size_t keylen,
-                      dbiIndexSet *set)
+static int dbiCursorGetToSet(dbiCursor dbc, const char *keyp, size_t keylen,
+                            dbiIndexSet *set)
 {
     int rc = EINVAL;
-    dbiCursor dbc = dbiCursorInit(dbi, 0);
     if (dbc != NULL) {
+       dbiIndex dbi = dbiCursorIndex(dbc);
        DBT data, key;
        memset(&data, 0, sizeof(data));
        memset(&key, 0, sizeof(key));
 
-       if (keyp && keylen == 0) {
-           keylen = strlen(keyp);
-           if (keylen == 0)
-               keylen++; /* XXX "/" fixup */
-       }
-
        key.data = (void *) keyp; /* discards const */
        key.size = keylen;
 
@@ -473,6 +467,25 @@ static int dbiGetToSet(dbiIndex dbi, const char *keyp, size_t keylen,
                   _("error(%d) getting \"%s\" records from %s index: %s\n"),
                   rc, keyp ? keyp : "???", dbiName(dbi), db_strerror(rc));
        }
+    }
+    return rc;
+}
+
+static int dbiGetToSet(dbiIndex dbi, const char *keyp, size_t keylen,
+                      dbiIndexSet *set)
+{
+    int rc = EINVAL;
+    if (dbi != NULL) {
+       dbiCursor dbc = dbiCursorInit(dbi, 0);
+
+       if (keyp && keylen == 0) {
+           keylen = strlen(keyp);
+           if (keylen == 0)
+               keylen++; /* XXX "/" fixup */
+       }
+
+       rc = dbiCursorGetToSet(dbc, keyp, keylen, set);
+
        dbiCursorFree(dbc);
     }
     return rc;