[Rpm-maint] [rpm-software-management/rpm] build: prioritize large packages (#1180)

Panu Matilainen notifications at github.com
Wed Apr 15 08:12:55 UTC 2020


@pmatilai commented on this pull request.



>  rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
 {
     rpmRC rc = RPMRC_OK;
     Package pkg;
+    Package *tasks;
+    int i = 0;
+
+    for (pkg = spec->packages; pkg != NULL; pkg = pkg->next)
+        i++;
+    tasks = xcalloc(i, sizeof(Package));
+    for (i = 0, pkg = spec->packages; pkg != NULL; i++, pkg = pkg->next)
+        tasks[i] = pkg;
+    qsort(tasks, i, sizeof(Package), compareBinaries);

Do use separate variables for indexing and things like total package count, (re)using an 'i' for multiple different purposes only makes the code harder to follow for now good reason. Using loop-local index variables is good way to ensure there are no side-effects from previous rounds, and also makes it obvious to the reader as well.

```
    int npkgs = 0;

    for (pkg = spec->packages; pkg != NULL; pkg = pkg->next)
        npkgs++;
    tasks = xcalloc(npkgs, sizeof(Package));
    for (int i = 0, pkg = spec->packages; pkg != NULL; i++, pkg = pkg->next)
        tasks[i] = pkg;
    qsort(tasks, npkgs, sizeof(Package), compareBinaries);
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1180#pullrequestreview-393549585
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20200415/be573f93/attachment.html>


More information about the Rpm-maint mailing list