From d435beb937ca38a3d3f1c6acb1b3ca06dcb3544d Mon Sep 17 00:00:00 2001
From: Michael Schroeder <mls@suse.de>
Date: Fri, 10 Jan 2020 11:51:07 +0100
Subject: [PATCH] ndb: no longer free the pkgid hash all the time

Reuse the hash if the size matches. This was actually the original
intention, but for some reason the code was disabled by always
freeing the hash.

URL:https://github.com/rpm-software-management/rpm/commit/d435beb937ca38a3d3f1c6acb1b3ca06dcb3544d
---
 lib/backend/ndb/rpmpkg.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/lib/backend/ndb/rpmpkg.c b/lib/backend/ndb/rpmpkg.c
index b613fa5..b95f29f 100644
--- a/lib/backend/ndb/rpmpkg.c
+++ b/lib/backend/ndb/rpmpkg.c
@@ -136,10 +136,6 @@ static int rpmpkgReadHeader(rpmpkgdb pkgdb)
     if (pkgdb->slots && (pkgdb->generation != generation || pkgdb->slotnpages != slotnpages)) {
 	free(pkgdb->slots);
 	pkgdb->slots = 0;
-	if (pkgdb->slothash) {
-	    free(pkgdb->slothash);
-	    pkgdb->slothash = 0;
-	}
     }
     pkgdb->generation = generation;
     pkgdb->slotnpages = slotnpages;
@@ -201,14 +197,14 @@ static int rpmpkgHashSlots(rpmpkgdb pkgdb)
     int i;
     pkgslot *slot;
 
-    pkgdb->nslothash = 0;
-    num = pkgdb->nslots;
+    num = pkgdb->nslots + 32;
     while (num & (num - 1))
 	num = num & (num - 1);
     num *= 4;
     hash = pkgdb->slothash;
     if (!hash || pkgdb->nslothash != num) {
-	free(pkgdb->slothash);
+	if (hash)
+	    free(hash);
 	hash = pkgdb->slothash = xcalloc(num, sizeof(unsigned int));
 	pkgdb->nslothash = num;
     } else {
@@ -221,8 +217,6 @@ static int rpmpkgHashSlots(rpmpkgdb pkgdb)
 	    ;
 	hash[h] = i + 1;
     }
-    pkgdb->slothash = hash;
-    pkgdb->nslothash = num;
     return RPMRC_OK;
 }
 
@@ -240,10 +234,6 @@ static int rpmpkgReadSlots(rpmpkgdb pkgdb)
 	free(pkgdb->slots);
 	pkgdb->slots = 0;
     }
-    if (pkgdb->slothash) {
-	free(pkgdb->slothash);
-	pkgdb->slothash = 0;
-    }
     pkgdb->nslots = 0;
     pkgdb->freeslot = 0;
 
-- 
1.8.3.1

