- speed up file list parsing a bit
authorMichael Schroeder <mls@suse.de>
Wed, 29 Jul 2009 17:00:20 +0000 (19:00 +0200)
committerMichael Schroeder <mls@suse.de>
Wed, 29 Jul 2009 17:00:20 +0000 (19:00 +0200)
ext/repo_rpmmd.c
src/pool.c
src/repodata.c

index 8c97ab2..f0b63a4 100644 (file)
@@ -249,6 +249,10 @@ struct parsedata {
   /** system language */
   const char *language;
 
+  Id lastdir;
+  char *lastdirstr;
+  int lastdirstrl;
+
   /** Hash to maps checksums to solv */
   Stringpool cspool;
   /** Cache of known checksums to solvable id */
@@ -829,24 +833,18 @@ startElement(void *userData, const char *name, const char **atts)
       {
         long filesz = 0, filenum = 0;
         unsigned dirid;
-        if ( (str = find_attr("name", atts)) )
-          {
-            dirid = repodata_str2dir(pd->data, str, 1);
-          }
+        if ((str = find_attr("name", atts)) != 0)
+          dirid = repodata_str2dir(pd->data, str, 1);
         else
           {
             fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n",
                     (void *)atts, *atts);
             break;
           }
-        if ( (str = find_attr("size", atts)) )
-          {
-            filesz = strtol (str, 0, 0);
-          }
-        if ( (str = find_attr("count", atts)) )
-          {
-            filenum = strtol (str, 0, 0);
-          }
+        if ((str = find_attr("size", atts)) != 0)
+          filesz = strtol(str, 0, 0);
+        if ((str = find_attr("count", atts)) != 0)
+          filenum = strtol(str, 0, 0);
         pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
         pd->dirs[pd->ndirs][0] = dirid;
         pd->dirs[pd->ndirs][1] = filesz;
@@ -898,8 +896,8 @@ endElement(void *userData, const char *name)
   switch (pd->state)
     {
     case STATE_SOLVABLE:
-      if ( pd->kind && !s->name ) /* add namespace in case of NULL name */
-        s->name = str2id(pool, join2( pd->kind, ":", ""), 1);
+      if (pd->kind && !s->name) /* add namespace in case of NULL name */
+        s->name = str2id(pool, join2(pd->kind, ":", ""), 1);
       if (!s->arch)
         s->arch = ARCH_NOARCH;
       if (!s->evr)
@@ -912,10 +910,10 @@ endElement(void *userData, const char *name)
       pd->kind = 0;
       break;
     case STATE_NAME:
-      if ( pd->kind )
-          s->name = str2id(pool, join2( pd->kind, ":", pd->content), 1);
+      if (pd->kind)
+        s->name = str2id(pool, join2(pd->kind, ":", pd->content), 1);
       else
-          s->name = str2id(pool, pd->content, 1);
+        s->name = str2id(pool, pd->content, 1);
       break;
     case STATE_ARCH:
       s->arch = str2id(pool, pd->content, 1);
@@ -970,7 +968,23 @@ endElement(void *userData, const char *name)
       if ((p = strrchr(pd->content, '/')) != 0)
        {
          *p++ = 0;
-         id = repodata_str2dir(pd->data, pd->content, 1);
+         if (pd->lastdir && !strcmp(pd->lastdirstr, pd->content))
+           {
+             id = pd->lastdir;
+           }
+         else
+           {
+             int l;
+             id = repodata_str2dir(pd->data, pd->content, 1);
+             l = strlen(pd->content) + 1;
+             if (l > pd->lastdirstrl)
+               {
+                 pd->lastdirstrl = l + 128;
+                 pd->lastdirstr = sat_realloc(pd->lastdirstr, pd->lastdirstrl);
+               }
+             strcpy(pd->lastdirstr, pd->content);
+             pd->lastdir = id;
+           }
        }
       else
        {
@@ -1038,7 +1052,7 @@ endElement(void *userData, const char *name)
       break;
     case STATE_DISKUSAGE:
       if (pd->ndirs)
-        commit_diskusage (pd, pd->handle);
+        commit_diskusage(pd, pd->handle);
       break;
     default:
       break;
@@ -1169,6 +1183,7 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
     }
   XML_ParserFree(parser);
   sat_free(pd.content);
+  sat_free(pd.lastdirstr);
   join_freemem();
   stringpool_free(&pd.cspool);
   sat_free(pd.cscache);
index 0702f7f..48bb5f2 100644 (file)
@@ -1005,6 +1005,11 @@ pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, stru
                  break;
              if (j < data->nkeys)
                {
+#if 0
+                 for (i = 0; i < cbd->nfiles; i++)
+                   if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
+                     printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
+#endif
                  for (i = 0; i < cbd->nfiles; i++)
                    if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
                      break;
index 28c3ca4..512080b 100644 (file)
@@ -241,7 +241,11 @@ repodata_str2dir(Repodata *data, const char *dir, int create)
   while (*dir == '/' && dir[1] == '/')
     dir++;
   if (*dir == '/' && !dir[1])
-    return 1;
+    {
+      if (data->dirpool.ndirs)
+        return 1;
+      return dirpool_add_dir(&data->dirpool, 0, 1, 1);
+    }
   while (*dir)
     {
       dire = strchrnul(dir, '/');