diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-06-08 13:15:02 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-06-08 13:15:02 +0300 |
commit | 224d1690e76724ba1fc4756aac23106dff90fab9 (patch) | |
tree | 87cad306239b2466647575c267e9c81ab38b7778 | |
parent | 81322e9742fc8b66fb23255ee35ca98e485ff3d7 (diff) | |
download | librpm-tizen-224d1690e76724ba1fc4756aac23106dff90fab9.tar.gz librpm-tizen-224d1690e76724ba1fc4756aac23106dff90fab9.tar.bz2 librpm-tizen-224d1690e76724ba1fc4756aac23106dff90fab9.zip |
Simplify + cleanup rpmdbExtendIterator()
- Use the new dbiGetToSet() for doing the actual work, reducing
fluff considerably
- Don't bother checking for NULLs where the lower levels do it
already (mi and keyp NULL-checks are necessary here though)
-rw-r--r-- | lib/rpmdb.c | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c index a94f03f90..aee27c4f3 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -1857,47 +1857,26 @@ void rpmdbSortIterator(rpmdbMatchIterator mi) int rpmdbExtendIterator(rpmdbMatchIterator mi, const void * keyp, size_t keylen) { - dbiCursor dbc; - DBT data, key; dbiIndex dbi = NULL; - dbiIndexSet set; - int rc; + dbiIndexSet set = NULL; + int rc = 1; /* assume failure */ if (mi == NULL || keyp == NULL) - return 1; - - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - key.data = (void *) keyp; - key.size = keylen ? keylen : strlen(keyp); - - dbi = rpmdbOpenIndex(mi->mi_db, mi->mi_rpmtag, 0); - if (dbi == NULL) - return 1; - - dbc = dbiCursorInit(dbi, 0); - rc = dbiCursorGet(dbc, &key, &data, DB_SET); - dbc = dbiCursorFree(dbc); - - if (rc) { /* error/not found */ - if (rc != DB_NOTFOUND) - rpmlog(RPMLOG_ERR, - _("error(%d) getting \"%s\" records from %s index\n"), - rc, (char*)key.data, dbiName(dbi)); return rc; - } - set = NULL; - (void) dbt2set(dbi, &data, &set); + dbi = rpmdbOpenIndex(mi->mi_db, mi->mi_rpmtag, 0); - if (mi->mi_set == NULL) { - mi->mi_set = set; - } else { - dbiGrowSet(mi->mi_set, set->count); - memcpy(mi->mi_set->recs + mi->mi_set->count, set->recs, - set->count * sizeof(*(mi->mi_set->recs))); - mi->mi_set->count += set->count; - set = dbiIndexSetFree(set); + if (dbiGetToSet(dbi, keyp, keylen, &set) == 0) { + if (mi->mi_set == NULL) { + mi->mi_set = set; + } else { + dbiGrowSet(mi->mi_set, set->count); + memcpy(mi->mi_set->recs + mi->mi_set->count, set->recs, + set->count * sizeof(*(mi->mi_set->recs))); + mi->mi_set->count += set->count; + dbiIndexSetFree(set); + } + rc = 0; } return rc; |