]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Save memory in repo_updateinfoxml by not interleaving repo_addflexarray calls
authorMichael Schroeder <mls@suse.de>
Thu, 20 Jul 2023 09:50:00 +0000 (11:50 +0200)
committerMichael Schroeder <mls@suse.de>
Thu, 20 Jul 2023 09:50:00 +0000 (11:50 +0200)
Mixing repo_addflexarray calls will make the code moving the arrays
in the idarraydata all the time as it cannot append to the arrays.
So first collect the array contents of the collection flexarray and
then add it in one go.

This is based on pull request #533 by Aleš Matěj <amatej@redhat.com>.

ext/repo_updateinfoxml.c

index 22f7093d81e88b2087bc235f9f1d2d53be1285a4..0725f03352ee9181f67b5d4e7d801dee3e31106c 100644 (file)
@@ -113,7 +113,7 @@ struct parsedata {
   Id pkghandle;
   struct solv_xmlparser xmlp;
   struct joindata jd;
-  Id collhandle;
+  Queue collectionq;
 };
 
 /*
@@ -289,9 +289,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
       break;
 
     case STATE_COLLECTION:
-      {
-        pd->collhandle = repodata_new_handle(pd->data);
-      }
+      queue_empty(&pd->collectionq);
       break;
 
       /*   <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
@@ -371,7 +369,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
         if (arch)
           repodata_set_poolstr(pd->data, module_handle, UPDATE_MODULE_ARCH, arch);
         repodata_add_flexarray(pd->data, pd->handle, UPDATE_MODULE, module_handle);
-        repodata_add_flexarray(pd->data, pd->collhandle, UPDATE_MODULE, module_handle);
+       queue_push2(&pd->collectionq, UPDATE_MODULE, module_handle);
         break;
       }
 
@@ -436,13 +434,19 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
       break;
 
     case STATE_COLLECTION:
-      repodata_add_flexarray(pd->data, pd->handle, UPDATE_COLLECTIONLIST, pd->collhandle);
-      pd->collhandle = 0;
+      {
+       Id collhandle = repodata_new_handle(pd->data);
+       int i;
+       for (i = 0; i < pd->collectionq.count; i += 2)
+         repodata_add_flexarray(pd->data, collhandle, pd->collectionq.elements[i], pd->collectionq.elements[i + 1]);
+       repodata_add_flexarray(pd->data, pd->handle, UPDATE_COLLECTIONLIST, collhandle);
+       queue_empty(&pd->collectionq);
+      }
       break;
 
     case STATE_PACKAGE:
       repodata_add_flexarray(pd->data, pd->handle, UPDATE_COLLECTION, pd->pkghandle);
-      repodata_add_flexarray(pd->data, pd->collhandle, UPDATE_COLLECTION, pd->pkghandle);
+      queue_push2(&pd->collectionq, UPDATE_COLLECTION, pd->pkghandle);
       pd->pkghandle = 0;
       break;
 
@@ -499,11 +503,13 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
   pd.pool = pool;
   pd.repo = repo;
   pd.data = data;
+  queue_init(&pd.collectionq);
   solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
   if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
     pd.ret = pool_error(pool, -1, "repo_updateinfoxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
   solv_xmlparser_free(&pd.xmlp);
   join_freemem(&pd.jd);
+  queue_free(&pd.collectionq);
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);