summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2017-08-03 13:29:10 +0200
committerPanu Matilainen <pmatilai@redhat.com>2018-03-28 13:25:23 +0300
commit29ee3e6110089e5c0fc268cb95e289c7fbdd701b (patch)
tree7c4addee7658e4df5dc3993702e44e9064b65a29
parent2340fd154ca117e563c4df050e7add7c2024a872 (diff)
downloadrpm-29ee3e6110089e5c0fc268cb95e289c7fbdd701b.tar.gz
Add dbiIndexSetAppendOne helper
Easier to use and faster than creating a record and using dbiIndexSetAppend. (cherry picked from commit a0e92e8b1f00ec3520a08279c59e9af1c97ca953)
-rw-r--r--lib/backend/dbiset.c16
-rw-r--r--lib/backend/dbiset.h12
-rw-r--r--lib/rpmdb.c13
3 files changed, 32 insertions, 9 deletions
diff --git a/lib/backend/dbiset.c b/lib/backend/dbiset.c
index 290a9ba5e..9ad143f28 100644
--- a/lib/backend/dbiset.c
+++ b/lib/backend/dbiset.c
@@ -100,6 +100,22 @@ int dbiIndexSetAppendSet(dbiIndexSet set, dbiIndexSet oset, int sortset)
return dbiIndexSetAppend(set, oset->recs, oset->count, sortset);
}
+int dbiIndexSetAppendOne(dbiIndexSet set, unsigned int hdrNum,
+ unsigned int tagNum, int sortset)
+{
+ if (set == NULL)
+ return 1;
+ dbiIndexSetGrow(set, 1);
+
+ set->recs[set->count].hdrNum = hdrNum;
+ set->recs[set->count].tagNum = tagNum;
+ set->count += 1;
+
+ if (sortset && set->count > 1)
+ qsort(set->recs, set->count, sizeof(*(set->recs)), hdrNumCmp);
+
+ return 0;
+}
int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs,
unsigned int nrecs, int sorted)
diff --git a/lib/backend/dbiset.h b/lib/backend/dbiset.h
index 7b106ba15..88182d24a 100644
--- a/lib/backend/dbiset.h
+++ b/lib/backend/dbiset.h
@@ -53,6 +53,18 @@ int dbiIndexSetAppend(dbiIndexSet set, dbiIndexItem recs,
unsigned int nrecs, int sortset);
/**
+ * Append a single element to a set of index database items.
+ * @param set set of index database items
+ * @param hdrNum header instance in db
+ * @param tagNum tag index in header
+ * @param sortset should resulting set be sorted?
+ * @return 0 success, 1 failure (bad args)
+ */
+RPM_GNUC_INTERNAL
+int dbiIndexSetAppendOne(dbiIndexSet set, unsigned int hdrNum,
+ unsigned int tagNum, int sortset);
+
+/**
* Remove element(s) from set of index database items.
* @param set set of index database items
* @param recs array of items to remove from set
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index c6718ab43..9469ede33 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -734,11 +734,8 @@ static rpmRC rpmdbFindByFile(rpmdb db, dbiIndex dbi, const char *filespec,
if (!skip) {
const char *dirName = dirNames[dirIndexes[num]];
if (fpLookupEquals(fpc, fp1, dirName, baseNames[num])) {
- struct dbiIndexItem_s rec = {
- .hdrNum = dbiIndexRecordOffset(allMatches, i),
- .tagNum = dbiIndexRecordFileNumber(allMatches, i),
- };
- dbiIndexSetAppend(*matches, &rec, 1, 0);
+ dbiIndexSetAppendOne(*matches, dbiIndexRecordOffset(allMatches, i),
+ dbiIndexRecordFileNumber(allMatches, i), 0);
}
}
@@ -1712,10 +1709,8 @@ int rpmdbAppendIterator(rpmdbMatchIterator mi,
if (mi->mi_set == NULL)
mi->mi_set = dbiIndexSetNew(nHdrNums);
- for (unsigned int i = 0; i < nHdrNums; i++) {
- struct dbiIndexItem_s rec = { .hdrNum = hdrNums[i], .tagNum = 0 };
- dbiIndexSetAppend(mi->mi_set, &rec, 1, 0);
- }
+ for (unsigned int i = 0; i < nHdrNums; i++)
+ dbiIndexSetAppendOne(mi->mi_set, hdrNums[i], 0, 0);
return 0;
}