]> err.no Git - dpkg/commitdiff
Increased the speed of convert_string() by a factor of 2, by storing the
authorAdam Heath <doogie@debian.org>
Tue, 26 Dec 2000 10:37:27 +0000 (10:37 +0000)
committerAdam Heath <doogie@debian.org>
Tue, 26 Dec 2000 10:37:27 +0000 (10:37 +0000)
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.

ChangeLog
include/dpkg-db.h
lib/fields.c
lib/parsehelp.c

index 48dd3b2000d01111178d50dfdceee9d6755da9ed..e5ca18c486c87861b3d24cbe7832df9a25b0be10 100644 (file)
--- a/ChangeLog
+++ b/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,
index 59fc76efc6db0c26e8203301143625ff52f21cb0..76a6f9287bba0de587a89ad61a08b88d47548107 100644 (file)
@@ -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[];
index f45e99e34d17a2f9d7eb874a08d3e43e329479d8..1dcb9ac00939d43ca46419e9128de890049e1ee5 100644 (file)
@@ -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);
index f79aebfe371c20b6d80d75b41681f82a282516b7..cb83df5d4e2207ac87939240e29a4d936d90394c 100644 (file)
@@ -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                           }
 };