From eff0c22e59e65b6b63e854ff41eb091278e05714 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 7 Jan 2016 19:16:23 +0100 Subject: Switch performance critical code to use APT::StringView This improves performance of the cache generation on my ARM platform (4x Cortex A15) by about 10% to 20% from 2.35-2.50 to 2.1 seconds. --- apt-pkg/contrib/hashsum_template.h | 26 +++++++++++++++++++++++++- apt-pkg/contrib/strutl.cc | 7 ++++++- apt-pkg/contrib/strutl.h | 7 ++++++- 3 files changed, 37 insertions(+), 3 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h index d0ea0971e..42248f6ac 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -13,6 +13,9 @@ #include #include +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include +#endif #include @@ -80,7 +83,16 @@ class HashSumValue { return Hex2Num(Str,Sum,sizeof(Sum)); } - +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN bool Set(APT::StringView Str) + { + return Hex2Num(Str,Sum,sizeof(Sum)); + } + APT_HIDDEN bool Set(const char *Str) + { + return Hex2Num(APT::StringView(Str),Sum,sizeof(Sum)); + } +#endif inline void Set(unsigned char S[N/8]) { for (int I = 0; I != sizeof(Sum); ++I) @@ -92,6 +104,18 @@ class HashSumValue memset(Sum,0,sizeof(Sum)); Set(Str); } +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN explicit HashSumValue(APT::StringView const &Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } + APT_HIDDEN explicit HashSumValue(const char *Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } +#endif HashSumValue() { memset(Sum,0,sizeof(Sum)); diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index b9bfc2c98..856e5ee9f 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1113,13 +1113,18 @@ static int HexDigit(int c) // --------------------------------------------------------------------- /* The length of the buffer must be exactly 1/2 the length of the string. */ bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length) +{ + return Hex2Num(APT::StringView(Str), Num, Length); +} + +bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length) { if (Str.length() != Length*2) return false; // Convert each digit. We store it in the same order as the string int J = 0; - for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2) + for (auto I = Str.begin(); I != Str.end();J++, I += 2) { int first_half = HexDigit(I[0]); int second_half; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index a8bbc38af..c5c8e2382 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -22,6 +22,9 @@ #include #include #include +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include +#endif #include #include @@ -75,7 +78,9 @@ bool StrToNum(const char *Str,unsigned long long &Res,unsigned Len,unsigned Base bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len); bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len); bool Hex2Num(const std::string &Str,unsigned char *Num,unsigned int Length); - +#ifdef APT_PKG_EXPOSE_STRING_VIEW +APT_HIDDEN bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length); +#endif // input changing string split bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); -- cgit v1.2.3