From c91a301f0fc238c9914ad8c1865233b209145bb3 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Tue, 26 Dec 2000 10:37:27 +0000 Subject: [PATCH] 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. --- ChangeLog | 7 ++++++ include/dpkg-db.h | 2 +- lib/fields.c | 15 +++++++++--- lib/parsehelp.c | 59 +++++++++++++++++++++++------------------------ 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48dd3b20..e5ca18c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Dec 26 04:34:02 CST 2000 Adam Heath + + * 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 * acconfig.h, config.h.bot, configure.in, main/filesdb.c, diff --git a/include/dpkg-db.h b/include/dpkg-db.h index 59fc76ef..76a6f928 100644 --- a/include/dpkg-db.h +++ b/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[]; diff --git a/lib/fields.c b/lib/fields.c index f45e99e3..1dcb9ac0 100644 --- a/lib/fields.c +++ b/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); diff --git a/lib/parsehelp.c b/lib/parsehelp.c index f79aebfe..cb83df5d 100644 --- a/lib/parsehelp.c +++ b/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 } }; -- 2.39.5