summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2017-08-03 13:21:49 +0200
committerPanu Matilainen <pmatilai@redhat.com>2018-03-28 13:25:23 +0300
commit2340fd154ca117e563c4df050e7add7c2024a872 (patch)
treee9d2ff53ffcf0608a8e5e668acb3f55b72189aff
parent51c67dee8fa44fe2e214a996f5f8f9ededa21d37 (diff)
downloadrpm-2340fd154ca117e563c4df050e7add7c2024a872.tar.gz
Remove duplicated code in dbiIndexSetAppendSet
Implement dbiIndexSetAppendSet in terms of dbiIndexSetAppend. Also, appending an empty set is not an error. (cherry picked from commit cb9bbf9d7da7cf1e7fc66cdac0a0cf4549b4e4c7)
-rw-r--r--lib/backend/dbiset.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/backend/dbiset.c b/lib/backend/dbiset.c
index ad0114e6e..290a9ba5e 100644
--- a/lib/backend/dbiset.c
+++ b/lib/backend/dbiset.c
@@ -75,30 +75,17 @@ void dbiIndexSetUniq(dbiIndexSet set, int sorted)
}
}
-int dbiIndexSetAppendSet(dbiIndexSet dest, dbiIndexSet src, int sortset)
-{
- if (dest == NULL || src == NULL || src->count == 0)
- return 1;
-
- dbiIndexSetGrow(dest, src->count);
- memcpy(dest->recs + dest->count,
- src->recs, src->count * sizeof(*src->recs));
- dest->count += src->count;
-
- if (sortset && dest->count > 1)
- qsort(dest->recs, dest->count, sizeof(*(dest->recs)), hdrNumCmp);
- return 0;
-}
-
int dbiIndexSetAppend(dbiIndexSet set, dbiIndexItem recs,
unsigned int nrecs, int sortset)
{
- if (set == NULL || recs == NULL || nrecs == 0)
+ if (set == NULL || recs == NULL)
return 1;
- dbiIndexSetGrow(set, nrecs);
- memcpy(set->recs + set->count, recs, nrecs * sizeof(*(set->recs)));
- set->count += nrecs;
+ if (nrecs) {
+ dbiIndexSetGrow(set, nrecs);
+ memcpy(set->recs + set->count, recs, nrecs * sizeof(*(set->recs)));
+ set->count += nrecs;
+ }
if (sortset && set->count > 1)
qsort(set->recs, set->count, sizeof(*(set->recs)), hdrNumCmp);
@@ -106,6 +93,14 @@ int dbiIndexSetAppend(dbiIndexSet set, dbiIndexItem recs,
return 0;
}
+int dbiIndexSetAppendSet(dbiIndexSet set, dbiIndexSet oset, int sortset)
+{
+ if (oset == NULL)
+ return 1;
+ return dbiIndexSetAppend(set, oset->recs, oset->count, sortset);
+}
+
+
int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs,
unsigned int nrecs, int sorted)
{