From 0d9fec8e6783006c0e62d31d4a28c4c6d35eca29 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 8 Jun 2011 18:46:45 +0300 Subject: [PATCH] Split actual cursor get + set-conversion to separate function - 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 | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index ce481be..4f831bb 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -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; -- 2.7.4