summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/debversion.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-07-13 12:47:05 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-08-10 17:27:18 +0200
commitfd23676e809b7fa87ae138cc22d2c683d212950e (patch)
treeb11da2587ec5bd22b1013f087c46f114f8d53d24 /apt-pkg/deb/debversion.cc
parent3707fd4faab3f2e2521263070b68fd0afaae2900 (diff)
bunch of micro-optimizations for depcache
DepCache functions are called a lot, so if we can squeeze some drops out of them for free we should do so. Takes also the opportunity to remove some whitespace errors from these functions. Git-Dch: Ignore
Diffstat (limited to 'apt-pkg/deb/debversion.cc')
-rw-r--r--apt-pkg/deb/debversion.cc47
1 files changed, 22 insertions, 25 deletions
diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc
index a5eacb7f5..043025912 100644
--- a/apt-pkg/deb/debversion.cc
+++ b/apt-pkg/deb/debversion.cc
@@ -34,29 +34,26 @@ debVersioningSystem::debVersioningSystem()
// debVS::CmpFragment - Compare versions /*{{{*/
// ---------------------------------------------------------------------
-/* This compares a fragment of the version. This is a slightly adapted
- version of what dpkg uses. */
-#define order(x) ((x) == '~' ? -1 \
- : isdigit((x)) ? 0 \
- : !(x) ? 0 \
- : isalpha((x)) ? (x) \
- : (x) + 256)
-int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
- const char *B,const char *BEnd)
+/* This compares a fragment of the version. This is a slightly adapted
+ version of what dpkg uses in dpkg/lib/dpkg/version.c.
+ In particular, the a | b = NULL check is removed as we check this in the
+ caller, we use an explicit end for a | b strings and we check ~ explicit. */
+static int order(char c)
{
- if (A >= AEnd && B >= BEnd)
+ if (isdigit(c))
return 0;
- if (A >= AEnd)
- {
- if (*B == '~') return 1;
+ else if (isalpha(c))
+ return c;
+ else if (c == '~')
return -1;
- }
- if (B >= BEnd)
- {
- if (*A == '~') return -1;
- return 1;
- }
-
+ else if (c)
+ return c + 256;
+ else
+ return 0;
+}
+int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
+ const char *B,const char *BEnd)
+{
/* Iterate over the whole string
What this does is to split the whole string into groups of
numeric and non numeric portions. For instance:
@@ -77,19 +74,19 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
int rc = order(*rhs);
if (vc != rc)
return vc - rc;
- lhs++; rhs++;
+ ++lhs; ++rhs;
}
while (*lhs == '0')
- lhs++;
+ ++lhs;
while (*rhs == '0')
- rhs++;
+ ++rhs;
while (isdigit(*lhs) && isdigit(*rhs))
{
if (!first_diff)
first_diff = *lhs - *rhs;
- lhs++;
- rhs++;
+ ++lhs;
+ ++rhs;
}
if (isdigit(*lhs))