- speed up array creation a bit by caching last values
authorMichael Schroeder <mls@suse.de>
Wed, 7 May 2008 17:00:21 +0000 (17:00 +0000)
committerMichael Schroeder <mls@suse.de>
Wed, 7 May 2008 17:00:21 +0000 (17:00 +0000)
src/repodata.c
src/repodata.h

index 910bfe84cc9e092b06f162aad807a6033606d1fa..387a16a0a99e7dff8b1376cbc844c63f0ba65d9c 100644 (file)
@@ -1405,6 +1405,14 @@ repodata_add_array(Repodata *data, Id handle, Id keyname, Id keytype, int entrys
   int oldsize;
   Id *ida, *pp;
 
+  if (handle == data->lasthandle && data->keys[data->lastkey].name == keyname && data->keys[data->lastkey].type == keytype && data->attriddatalen == data->lastdatalen)
+    {
+      /* great! just append the new data */
+      data->attriddata = sat_extend(data->attriddata, data->attriddatalen, entrysize, sizeof(Id), REPODATA_ATTRIDDATA_BLOCK);
+      data->attriddatalen--;   /* overwrite terminating 0  */
+      data->lastdatalen += entrysize;
+      return;
+    }
   pp = data->structs[handle];
   if (pp)
     for (; *pp; pp += 2)
@@ -1420,6 +1428,7 @@ repodata_add_array(Repodata *data, Id handle, Id keyname, Id keytype, int entrys
       key.storage = KEY_STORAGE_INCORE;
       data->attriddata = sat_extend(data->attriddata, data->attriddatalen, entrysize + 1, sizeof(Id), REPODATA_ATTRIDDATA_BLOCK);
       repodata_set(data, handle, &key, data->attriddatalen);
+      data->lasthandle = 0;    /* next time... */
       return;
     }
   oldsize = 0;
@@ -1439,6 +1448,9 @@ repodata_add_array(Repodata *data, Id handle, Id keyname, Id keytype, int entrys
       pp[1] = data->attriddatalen;
       data->attriddatalen += oldsize;
     }
+  data->lasthandle = handle;
+  data->lastkey = *pp;
+  data->lastdatalen = data->attriddatalen + entrysize + 1;
 }
 
 static inline int
@@ -1998,6 +2010,9 @@ fprintf(stderr, "schemadata %p\n", data->schemadata);
     if (data->structs[entry])
       sat_free(data->structs[entry]);
   data->structs = sat_free(data->structs);
+  data->lasthandle = 0;
+  data->lastkey = 0;
+  data->lastdatalen = 0;
   sat_free(schema);
   sat_free(seen);
 
index abf611f477509ce31b303c71238f4b2d7d2c4d82..ca9bbe1061804f36313ed4d2776d93054b7a67cd 100644 (file)
@@ -111,6 +111,11 @@ typedef struct _Repodata {
   Id **structs;                        /* key-value lists */
   unsigned int nstructs;
 
+  /* array cache */
+  Id lasthandle;
+  Id lastkey;
+  Id lastdatalen;
+
   Id *addedfileprovides;
 } Repodata;