- save memory in localpool case
authorMichael Schroeder <mls@suse.de>
Mon, 26 Nov 2012 12:24:08 +0000 (13:24 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 26 Nov 2012 12:24:08 +0000 (13:24 +0100)
We mis-use the old hashmask as indication if we have the correct blocking, as
we don't want to break ABI compat right now.

src/repo_solv.c
src/strpool.c

index 0f967b9..53792fa 100644 (file)
@@ -576,9 +576,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
     {
       data.localpool = 1;
       spool = &data.spool;
-      spool->sstrings = 7 + sizeid + 1;
-      spool->nstrings = numid < 2 ? 2 : numid;
-      stringpool_shrink(spool);                /* we misuse stringpool_shrink to alloc the stringpool in the correct size */
+      spool->stringspace = solv_malloc(7 + sizeid + 1); 
+      spool->strings = solv_malloc2(numid < 2 ?  2 : numid, sizeof(Offset));
       strcpy(spool->stringspace, "<NULL>");
       spool->sstrings = 7;
       spool->nstrings = 1;
@@ -657,6 +656,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
     }
   else
     {
+      Offset oldsstrings = spool->sstrings;
+
       /* alloc id map for name and rel Ids. this maps ids in the solv files
        * to the ids in our pool */
       idmap = solv_calloc(numid + numrel, sizeof(Id));
@@ -695,8 +696,10 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
        {
          if (sp >= strsp + sizeid)
            {
-             solv_free(hashtbl);
              solv_free(idmap);
+             spool->nstrings = oldnstrings;
+             spool->sstrings = oldsstrings;
+             stringpool_freehash(spool);
              return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings %d %d", i, numid);
            }
          if (!*sp)                            /* empty string */
index 0d92beb..5a9c64a 100644 (file)
@@ -81,7 +81,7 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create
 {
   Hashval h;
   unsigned int hh;
-  Hashmask hashmask;
+  Hashmask hashmask, oldhashmask;
   int i;
   Id id;
   Hashtable hashtbl;
@@ -91,7 +91,7 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create
   if (!len)
     return STRID_EMPTY;
 
-  hashmask = ss->stringhashmask;
+  hashmask = oldhashmask = ss->stringhashmask;
   hashtbl = ss->stringhashtbl;
 
   /* expand hashtable if needed */
@@ -127,6 +127,16 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create
   if (id || !create)    /* exit here if string found */
     return id;
 
+  /* this should be a test for a flag that tells us if the 
+   * correct blocking is used, but adding a flag would break
+   * the ABI. So we use the existance of the hash area as
+   * indication instead */
+  if (!oldhashmask)
+    {
+      ss->stringspace = solv_extend_resize(ss->stringspace, ss->sstrings + len + 1, 1, STRINGSPACE_BLOCK);
+      ss->strings = solv_extend_resize(ss->strings, ss->nstrings + 1, sizeof(Offset), STRING_BLOCK);
+    }
+
   /* generate next id and save in table */
   id = ss->nstrings++;
   hashtbl[h] = id;