Sfoglia il codice sorgente

Increased the speed of convert_string() by a factor of 2, by storing the
length of each string inside the struct(this function is used to convert
strings into integer values).

This is the first speedup discovered by using gprof.

Adam Heath 25 anni fa
parent
commit
c91a301f0f
4 ha cambiato i file con 49 aggiunte e 34 eliminazioni
  1. 7 0
      ChangeLog
  2. 1 1
      include/dpkg-db.h
  3. 12 3
      lib/fields.c
  4. 29 30
      lib/parsehelp.c

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+Tue Dec 26 04:34:02 CST 2000 Adam Heath <doogie@debian.org>
+
+  * lib/fields.c, lib/parsehelp.c, include/dpkg-db.h: Increased the
+    speed of convert_string() by a factor of 2, by storing the length
+    of each string inside the struct(this function is used to convert
+    strings into integer values).
+
 Tue Dec 26 03:43:17 CST 2000 Adam Heath <doogie@debian.org>
 
   * acconfig.h, config.h.bot, configure.in, main/filesdb.c,

+ 1 - 1
include/dpkg-db.h

@@ -200,7 +200,7 @@ void copy_dependency_links(struct pkginfo *pkg,
 
 struct namevalue {
   const char *name;
-  int value;
+  int value, length;
 };
 
 extern const struct namevalue booleaninfos[];

+ 12 - 3
lib/fields.c

@@ -39,14 +39,23 @@ static int convert_string
 
   ep= startp;
   if (!*ep) parseerr(0,filename,lno, warnto,warncount,pigp,0, _("%s is missing"),what);
-  while ((c= *ep) && !isspace(c)) ep++;
-  l= (int)(ep-startp);
-  while (nvip->name && (strncasecmp(nvip->name,startp,l) || nvip->name[l])) nvip++;
+  while (nvip->name) {
+    if ((l= nvip->length) == 0) {
+      l= strlen(nvip->name);
+      ((struct namevalue *)nvip)->length= l;
+    }
+    if (strncasecmp(nvip->name,startp,l) || nvip->name[l])
+      nvip++;
+    else
+      break;
+  }
   if (!nvip->name) {
     if (otherwise != -1) return otherwise;
     parseerr(0,filename,lno, warnto,warncount,pigp,0, _("`%.*s' is not allowed for %s"),
              l > 50 ? 50 : l, startp, what);
   }
+  ep = startp + l;
+  c = *ep;
   while (isspace(c)) c= *++ep;
   if (c && !endpp)
     parseerr(0,filename,lno, warnto,warncount,pigp,0, _("junk after %s"),what);

+ 29 - 30
lib/parsehelp.c

@@ -56,53 +56,52 @@ void parseerr
 }
 
 const struct namevalue booleaninfos[]= {  /* Note !  These must be in order ! */
-  { "no",                             0                  },
-  { "yes",                            1                  },
+  { "no",                             0,                 2 },
+  { "yes",                            1,                 3 },
   {  0                                                   }
 };
 
 const struct namevalue priorityinfos[]= {  /* Note !  These must be in order ! */
-  { "required",                       pri_required     },
-  { "important",                      pri_important    },
-  { "standard",                       pri_standard     },
-  { "recommended",                    pri_recommended  }, /* fixme: obsolete */
-  { "optional",                       pri_optional     },
-  { "extra",                          pri_extra        },
-  { "contrib",                        pri_contrib      }, /* fixme: keep? */
-  { "this is a bug - please report",  pri_other        },
-  { "unknown",                        pri_unknown      },
-  
-  { "base",                           pri_required     }, /* fixme: alias, remove */
+  { "required",                       pri_required,     8 },
+  { "important",                      pri_important,    9 },
+  { "standard",                       pri_standard,     8 },
+  { "recommended",                    pri_recommended,  11 }, /* fixme: obsolete */
+  { "optional",                       pri_optional,     8 },
+  { "extra",                          pri_extra,        5 },
+  { "contrib",                        pri_contrib,      7 }, /* fixme: keep? */
+  { "this is a bug - please report",  pri_other,        28 },
+  { "unknown",                        pri_unknown,      7 },
+  { "base",                           pri_required,     4 }, /* fixme: alias, remove */
   {  0                                                 }
 };
 
 const struct namevalue statusinfos[]= {  /* Note !  These must be in order ! */
-  { "not-installed",   stat_notinstalled    },
-  { "unpacked",        stat_unpacked        },
-  { "half-configured", stat_halfconfigured  },
-  { "installed",       stat_installed       },
-  { "half-installed",  stat_halfinstalled   },
-  { "config-files",    stat_configfiles     },
+  { "not-installed",   stat_notinstalled,    13 },
+  { "unpacked",        stat_unpacked,        8 },
+  { "half-configured", stat_halfconfigured,  15, },
+  { "installed",       stat_installed,       9 },
+  { "half-installed",  stat_halfinstalled,   14 },
+  { "config-files",    stat_configfiles,     12 },
   /* These are additional entries for reading only, in any order ... */
-  { "postinst-failed", stat_halfconfigured  }, /* fixme: backwards compat., remove */
-  { "removal-failed",  stat_halfinstalled   }, /* fixme: backwards compat., remove */
+  { "postinst-failed", stat_halfconfigured,  15 }, /* fixme: backwards compat., remove */
+  { "removal-failed",  stat_halfinstalled,   14 }, /* fixme: backwards compat., remove */
   {  0                                      }
 };
 
 const struct namevalue eflaginfos[]= {  /* Note !  These must be in order ! */
-  { "ok",                      eflagv_ok                 },
-  { "reinstreq",               eflagv_reinstreq          },
-  { "hold",                    eflagv_obsoletehold       },
-  { "hold-reinstreq",          eflagv_obsoleteboth       },
+  { "ok",                      eflagv_ok,                2 },
+  { "reinstreq",               eflagv_reinstreq,         9 },
+  { "hold",                    eflagv_obsoletehold,      4 },
+  { "hold-reinstreq",          eflagv_obsoleteboth,      14 },
   {  0                                                   }
 };
 
 const struct namevalue wantinfos[]= {  /* Note !  These must be in order ! */
-  { "unknown",   want_unknown    },
-  { "install",   want_install    },
-  { "hold",      want_hold       },
-  { "deinstall", want_deinstall  },
-  { "purge",     want_purge      },
+  { "unknown",   want_unknown,    7 },
+  { "install",   want_install,    7 },
+  { "hold",      want_hold,       4 },
+  { "deinstall", want_deinstall,  9 },
+  { "purge",     want_purge,      5 },
   {  0                           }
 };