[PATCH] speed up debVersioningSystem::DoCmpVersion a bit (v2)
modified according to comments by jak@debian.org
---
apt-pkg/deb/debversion.cc | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc
index 1405612..4762b93 100644
--- a/apt-pkg/deb/debversion.cc
+++ b/apt-pkg/deb/debversion.cc
@@ -119,21 +119,38 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
// Shouldnt happen
return 1;
}
+
/*}}}*/
// debVS::CmpVersion - Comparison for versions /*{{{*/
// ---------------------------------------------------------------------
+static const char *memchr_short(const char *s, int c, size_t n)
+{
+ const char *p = s;
+ while (p != s+n) {
+ if (*p == c) return p;
+ p++;
+ }
+ return s;
+}
+
+static const char *memrchr_short(const char *s, int c, size_t n)
+{
+ const char *p = s+n;
+ while (p != s) {
+ p--;
+ if (*p == c) return p;
+ }
+ return s+n;
+}
+
/* This fragments the version into E:V-R triples and compares each
portion separately. */
int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
const char *B,const char *BEnd)
{
// Strip off the epoch and compare it
- const char *lhs = (const char*) memchr(A, ':', AEnd - A);
- const char *rhs = (const char*) memchr(B, ':', BEnd - B);
- if (lhs == NULL)
- lhs = A;
- if (rhs == NULL)
- rhs = B;
+ const char *lhs = memchr_short(A, ':', AEnd - A);
+ const char *rhs = memchr_short(B, ':', BEnd - B);
// Special case: a zero epoch is the same as no epoch,
// so remove it.
@@ -168,12 +185,8 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
rhs++;
// Find the last -
- const char *dlhs = (const char*) memrchr(lhs, '-', AEnd - lhs);
- const char *drhs = (const char*) memrchr(rhs, '-', BEnd - rhs);
- if (dlhs == NULL)
- dlhs = AEnd;
- if (drhs == NULL)
- drhs = BEnd;
+ const char *dlhs = memrchr_short(lhs, '-', AEnd - A);
+ const char *drhs = memrchr_short(rhs, '-', BEnd - B);
// Compare the main version
Res = CmpFragment(lhs,dlhs,rhs,drhs);
--
1.7.10.4
Reply to: