[PATCH 1/3] speed up debVersioningSystem::DoCmpVersion a bit
---
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..6b75e66 100644
--- a/apt-pkg/deb/debversion.cc
+++ b/apt-pkg/deb/debversion.cc
@@ -119,6 +119,27 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
// Shouldnt happen
return 1;
}
+
+const char *memchr_short(const char *s, int c, const char *e)
+{
+ const char *p = s;
+ while (p != e) {
+ if (*p == c) return p;
+ p++;
+ }
+ return s;
+}
+
+const char *memrchr_short(const char *s, int c, const char *e)
+{
+ const char *p = e;
+ while (p != s) {
+ p--;
+ if (*p == c) return p;
+ }
+ return e;
+}
+
/*}}}*/
// debVS::CmpVersion - Comparison for versions /*{{{*/
// ---------------------------------------------------------------------
@@ -128,12 +149,8 @@ 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 = (const char*) memchr_short(A, ':', AEnd);
+ const char *rhs = (const char*) memchr_short(B, ':', BEnd);
// 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 = (const char*) memrchr_short(lhs, '-', AEnd);
+ const char *drhs = (const char*) memrchr_short(rhs, '-', BEnd);
// Compare the main version
Res = CmpFragment(lhs,dlhs,rhs,drhs);
--
1.7.10.4
Reply to: