Title: [103144] trunk/Source/_javascript_Core
Revision
103144
Author
benja...@webkit.org
Date
2011-12-16 22:35:29 -0800 (Fri, 16 Dec 2011)

Log Message

Remove the duplicated code from ASCIICType.h
https://bugs.webkit.org/show_bug.cgi?id=74771

Patch by Benjamin Poulain <bpoul...@apple.com> on 2011-12-16
Reviewed by Andreas Kling.

The functions were sharing similar code and were defined for the various input types.
Use templates instead to avoid code duplication.

* wtf/ASCIICType.h:
(WTF::isASCII):
(WTF::isASCIIAlpha):
(WTF::isASCIIAlphanumeric):
(WTF::isASCIIDigit):
(WTF::isASCIIHexDigit):
(WTF::isASCIILower):
(WTF::isASCIIOctalDigit):
(WTF::isASCIIPrintable):
(WTF::isASCIISpace):
(WTF::isASCIIUpper):
(WTF::toASCIILower):
(WTF::toASCIIUpper):
(WTF::toASCIIHexValue):
(WTF::lowerNibbleToASCIIHexDigit):
(WTF::upperNibbleToASCIIHexDigit):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (103143 => 103144)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-17 05:53:42 UTC (rev 103143)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-17 06:35:29 UTC (rev 103144)
@@ -1,3 +1,30 @@
+2011-12-16  Benjamin Poulain  <bpoul...@apple.com>
+
+        Remove the duplicated code from ASCIICType.h
+        https://bugs.webkit.org/show_bug.cgi?id=74771
+
+        Reviewed by Andreas Kling.
+
+        The functions were sharing similar code and were defined for the various input types.
+        Use templates instead to avoid code duplication.
+
+        * wtf/ASCIICType.h:
+        (WTF::isASCII):
+        (WTF::isASCIIAlpha):
+        (WTF::isASCIIAlphanumeric):
+        (WTF::isASCIIDigit):
+        (WTF::isASCIIHexDigit):
+        (WTF::isASCIILower):
+        (WTF::isASCIIOctalDigit):
+        (WTF::isASCIIPrintable):
+        (WTF::isASCIISpace):
+        (WTF::isASCIIUpper):
+        (WTF::toASCIILower):
+        (WTF::toASCIIUpper):
+        (WTF::toASCIIHexValue):
+        (WTF::lowerNibbleToASCIIHexDigit):
+        (WTF::upperNibbleToASCIIHexDigit):
+
 2011-12-16  Gavin Barraclough  <barraclo...@apple.com>
 
         Reverted r103120, this breaks v8 on ARMv7 DFG.

Modified: trunk/Source/_javascript_Core/wtf/ASCIICType.h (103143 => 103144)


--- trunk/Source/_javascript_Core/wtf/ASCIICType.h	2011-12-17 05:53:42 UTC (rev 103143)
+++ trunk/Source/_javascript_Core/wtf/ASCIICType.h	2011-12-17 06:35:29 UTC (rev 103144)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -43,129 +43,105 @@
 
 namespace WTF {
 
-    inline bool isASCII(char c) { return !(c & ~0x7F); }
-    inline bool isASCII(unsigned short c) { return !(c & ~0x7F); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCII(wchar_t c) { return !(c & ~0x7F); }
-#endif
-    inline bool isASCII(int c) { return !(c & ~0x7F); }
-    inline bool isASCII(unsigned c) { return !(c & ~0x7F); }
+template<typename CharType> inline bool isASCII(CharType c)
+{
+    return !(c & ~0x7F);
+}
 
-    inline bool isASCIIAlpha(char c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
-    inline bool isASCIIAlpha(unsigned short c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIAlpha(wchar_t c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
-#endif
-    inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
-    inline bool isASCIIAlpha(unsigned c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
+template<typename CharType> inline bool isASCIIAlpha(CharType c)
+{
+    return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
+}
 
-    inline bool isASCIIAlphanumeric(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
-    inline bool isASCIIAlphanumeric(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIAlphanumeric(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
-#endif
-    inline bool isASCIIAlphanumeric(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
-    inline bool isASCIIAlphanumeric(unsigned c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
+template<typename CharType> inline bool isASCIIAlphanumeric(CharType c)
+{
+    return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z');
+}
 
-    inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); }
-    inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9'); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIDigit(wchar_t c) { return (c >= '0') & (c <= '9'); }
-#endif
-    inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); }
-    inline bool isASCIIDigit(unsigned c) { return (c >= '0') & (c <= '9'); }
+template<typename CharType> inline bool isASCIIDigit(CharType c)
+{
+    return (c >= '0') & (c <= '9');
+}
 
-    inline bool isASCIIHexDigit(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
-    inline bool isASCIIHexDigit(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIHexDigit(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
-#endif
-    inline bool isASCIIHexDigit(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
-    inline bool isASCIIHexDigit(unsigned c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
+template<typename CharType> inline bool isASCIIHexDigit(CharType c)
+{
+    return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
+}
 
-    inline bool isASCIIOctalDigit(char c) { return (c >= '0') & (c <= '7'); }
-    inline bool isASCIIOctalDigit(unsigned short c) { return (c >= '0') & (c <= '7'); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIOctalDigit(wchar_t c) { return (c >= '0') & (c <= '7'); }
-#endif
-    inline bool isASCIIOctalDigit(int c) { return (c >= '0') & (c <= '7'); }
-    inline bool isASCIIOctalDigit(unsigned c) { return (c >= '0') & (c <= '7'); }
+template<typename CharType> inline bool isASCIILower(CharType c)
+{
+    return c >= 'a' && c <= 'z';
+}
 
-    inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; }
-    inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIILower(wchar_t c) { return c >= 'a' && c <= 'z'; }
-#endif
-    inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; }
-    inline bool isASCIILower(unsigned c) { return c >= 'a' && c <= 'z'; }
+template<typename CharType> inline bool isASCIIOctalDigit(CharType c)
+{
+    return (c >= '0') & (c <= '7');
+}
 
-    inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; }
-    inline bool isASCIIUpper(unsigned short c) { return c >= 'A' && c <= 'Z'; }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIUpper(wchar_t c) { return c >= 'A' && c <= 'Z'; }
-#endif
-    inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; }
-    inline bool isASCIIUpper(unsigned c) { return c >= 'A' && c <= 'Z'; }
+template<typename CharType> inline bool isASCIIPrintable(CharType c)
+{
+    return c >= ' ' && c <= '~';
+}
 
-    /*
-        Statistics from a run of Apple's page load test for callers of isASCIISpace:
+/*
+ Statistics from a run of Apple's page load test for callers of isASCIISpace:
 
-            character          count
-            ---------          -----
-            non-spaces         689383
-        20  space              294720
-        0A  \n                 89059
-        09  \t                 28320
-        0D  \r                 0
-        0C  \f                 0
-        0B  \v                 0
-    */
-    inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
-    inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIISpace(wchar_t c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
-#endif
-    inline bool isASCIISpace(int c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
-    inline bool isASCIISpace(unsigned c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
+ character          count
+ ---------          -----
+ non-spaces         689383
+ 20  space          294720
+ 0A  \n             89059
+ 09  \t             28320
+ 0D  \r             0
+ 0C  \f             0
+ 0B  \v             0
+ */
+template<typename CharType> inline bool isASCIISpace(CharType c)
+{
+    return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
+}
 
-    inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
-    inline unsigned short toASCIILower(unsigned short c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline wchar_t toASCIILower(wchar_t c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
-#endif
-    inline int toASCIILower(int c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
-    inline unsigned toASCIILower(unsigned c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
+template<typename CharType> inline bool isASCIIUpper(CharType c)
+{
+    return c >= 'A' && c <= 'Z';
+}
 
-    // FIXME: Why do these need static_cast?
-    inline char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5)); }
-    inline unsigned short toASCIIUpper(unsigned short c) { return static_cast<unsigned short>(c & ~((c >= 'a' && c <= 'z') << 5)); }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline wchar_t toASCIIUpper(wchar_t c) { return static_cast<wchar_t>(c & ~((c >= 'a' && c <= 'z') << 5)); }
-#endif
-    inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5)); }
-    inline unsigned toASCIIUpper(unsigned c) { return static_cast<unsigned>(c & ~((c >= 'a' && c <= 'z') << 5)); }
+template<typename CharType> inline CharType toASCIILower(CharType c)
+{
+    return c | ((c >= 'A' && c <= 'Z') << 5);
+}
 
-    inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
-    inline int toASCIIHexValue(char upperValue, char lowerValue) { ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue)); return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue); }
-    inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
-#endif
-    inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
-    inline int toASCIIHexValue(unsigned c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
+template<typename CharType> inline CharType toASCIIUpper(CharType c)
+{
+    return c & ~((c >= 'a' && c <= 'z') << 5);
+}
 
-    inline char lowerNibbleToASCIIHexDigit(char c) { char nibble = c & 0xF; return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; }
-    inline char upperNibbleToASCIIHexDigit(char c) { char nibble = (c >> 4) & 0xF; return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; }
+template<typename CharType> inline int toASCIIHexValue(CharType c)
+{
+    ASSERT(isASCIIHexDigit(c));
+    return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
+}
 
-    inline bool isASCIIPrintable(char c) { return c >= ' ' && c <= '~'; }
-    inline bool isASCIIPrintable(unsigned short c) { return c >= ' ' && c <= '~'; }
-#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
-    inline bool isASCIIPrintable(wchar_t c) { return c >= ' ' && c <= '~'; }
-#endif
-    inline bool isASCIIPrintable(int c) { return c >= ' ' && c <= '~'; }
-    inline bool isASCIIPrintable(unsigned c) { return c >= ' ' && c <= '~'; }
+template<typename CharType> inline int toASCIIHexValue(CharType upperValue, CharType lowerValue)
+{
+    ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue));
+    return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue);
 }
 
+inline char lowerNibbleToASCIIHexDigit(char c)
+{
+    char nibble = c & 0xF;
+    return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
+}
+
+inline char upperNibbleToASCIIHexDigit(char c)
+{
+    char nibble = (c >> 4) & 0xF;
+    return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
+}
+
+}
+
 using WTF::isASCII;
 using WTF::isASCIIAlpha;
 using WTF::isASCIIAlphanumeric;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to