]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Speed up build-id provides queries
authorMichael Schroeder <mls@suse.de>
Mon, 24 Apr 2017 12:28:45 +0000 (14:28 +0200)
committerMichael Schroeder <mls@suse.de>
Mon, 24 Apr 2017 12:28:45 +0000 (14:28 +0200)
They are of the form "foo = md5sum", which is very expensive
because of rpm's evr comparison rules.

src/pool.c

index 1adf70e33b4b27a02292c2c7c4d66c6c24049681..d427552a86ff788974591c03daf1f8a3803543be 100644 (file)
@@ -997,6 +997,45 @@ pool_is_kind(Pool *pool, Id name, Id kind)
     }
 }
 
+/*
+ * rpm eq magic:
+ *
+ * some dependencies are of the from "foo = md5sum", like the
+ * buildid provides. There's not much we can do to speed up
+ * getting the providers, because rpm's complex evr comparison
+ * rules get in the way. But we can use the first character(s)
+ * of the md5sum to do a simple pre-check.
+ */
+static inline int
+rpmeqmagic(const char *s)
+{
+  if (*s == '0')
+    {
+      while (*s == '0' && s[1] >= '0' && s[1] <= '9')
+       s++;
+      /* ignore epoch 0 */
+      if (*s == '0' && s[1] == ':')
+       {
+         s += 2;
+         while (*s == '0' && s[1] >= '0' && s[1] <= '9')
+           s++;
+       }
+    }
+  if (*s >= '0' && *s <= '9')
+    {
+      if (s[1] >= '0' && s[1] <= '9')
+        return *s + (s[1] << 8);
+      return *s;
+    }
+  if ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z'))
+    {
+      if ((s[1] >= 'a' && s[1] <= 'z') || (s[1] >= 'A' && s[1] <= 'Z'))
+        return *s + (s[1] << 8);
+      return *s;
+    }
+  return -1;
+}
+
 /*
  * addrelproviders
  *
@@ -1218,6 +1257,7 @@ pool_addrelproviders(Pool *pool, Id d)
   else if (flags)
     {
       Id *ppaux = 0;
+      int eqmagic = 0;
       /* simple version comparison relation */
 #if 0
       POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
@@ -1268,6 +1308,13 @@ pool_addrelproviders(Pool *pool, Id d)
                queue_push(&plist, p);
              continue;
            }
+         if (!eqmagic)
+           {
+             if (flags != REL_EQ || pool->disttype != DISTTYPE_RPM || pool->promoteepoch || ISRELDEP(evr))
+               eqmagic = -1;
+             else
+               eqmagic = rpmeqmagic(pool_id2str(pool, evr));
+           }
          /* solvable p provides name in some rels */
          pidp = s->repo->idarraydata + s->provides;
          while ((pid = *pidp++) != 0)
@@ -1284,6 +1331,12 @@ pool_addrelproviders(Pool *pool, Id d)
              if (prd->name != name)
                continue;               /* wrong provides name */
              /* right package, both deps are rels. check flags/evr */
+             if (eqmagic > 0 && prd->flags == REL_EQ && !ISRELDEP(prd->evr))
+               {
+                 int peqmagic = rpmeqmagic(pool_id2str(pool, prd->evr));
+                 if (peqmagic > 0 && peqmagic != eqmagic)
+                   continue;
+               }
              if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
                break;  /* matches */
            }