Explorar o código

Turn tolower_ascii() and isspace_ascii() into inline functions

To preserve compatibility, the new inline functions have _inline
as a suffix, and a macro defines the old names to refer to the
inline variants.

The old functions are still preserved for binary compatibility.

Also simplify the implementation of both functions.
Julian Andres Klode %!s(int64=10) %!d(string=hai) anos
pai
achega
98eb4e9eec
Modificáronse 2 ficheiros con 21 adicións e 11 borrados
  1. 5 9
      apt-pkg/contrib/strutl.cc
  2. 16 2
      apt-pkg/contrib/strutl.h

+ 5 - 9
apt-pkg/contrib/strutl.cc

@@ -1369,17 +1369,17 @@ string StripEpoch(const string &VerStr)
    return VerStr.substr(i+1);
 }
 									/*}}}*/
+
 // tolower_ascii - tolower() function that ignores the locale		/*{{{*/
 // ---------------------------------------------------------------------
 /* This little function is the most called method we have and tries
    therefore to do the absolut minimum - and is notable faster than
    standard tolower/toupper and as a bonus avoids problems with different
    locales - we only operate on ascii chars anyway. */
+#undef tolower_ascii
 int tolower_ascii(int const c)
 {
-   if (c >= 'A' && c <= 'Z')
-      return c + 32;
-   return c;
+   return tolower_ascii_inline(c);
 }
 									/*}}}*/
 
@@ -1389,14 +1389,10 @@ int tolower_ascii(int const c)
    therefore to do the absolut minimum - and is notable faster than
    standard isspace() and as a bonus avoids problems with different
    locales - we only operate on ascii chars anyway. */
+#undef isspace_ascii
 int isspace_ascii(int const c)
 {
-   return (c == ' '
-           || c == '\f'
-           || c == '\n'
-           || c == '\r'
-           || c == '\t'
-           || c == '\v');
+   return isspace_ascii_inline(c);
 }
 									/*}}}*/
 

+ 16 - 2
apt-pkg/contrib/strutl.h

@@ -105,8 +105,22 @@ void ioprintf(std::ostream &out,const char *format,...) APT_PRINTF(2);
 void strprintf(std::string &out,const char *format,...) APT_PRINTF(2);
 char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_PRINTF(3);
 bool CheckDomainList(const std::string &Host, const std::string &List);
-int tolower_ascii(int const c) APT_CONST APT_HOT;
-int isspace_ascii(int const c) APT_CONST APT_HOT;
+
+/* Do some compat mumbo jumbo */
+#define tolower_ascii  tolower_ascii_inline
+#define isspace_ascii  isspace_ascii_inline
+
+APT_CONST APT_HOT
+static inline int tolower_ascii_inline(int const c)
+{
+   return (c >= 'A' && c <= 'Z') ? c + 32 : c;
+}
+APT_CONST APT_HOT
+static inline int isspace_ascii_inline(int const c)
+{
+   // 9='\t',10='\n',11='\v',12='\f',13='\r',32=' '
+   return (c >= 9 && c <= 13) || c == ' ';
+}
 
 std::string StripEpoch(const std::string &VerStr);