Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1424)

Side by Side Diff: Source/wtf/ASCIICType.h

Issue 1177163003: Faster WTF::toASCIILower() implementation for 8-bit strings (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed unit test coding style Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/ASCIICTypeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #ifndef WTF_ASCIICType_h 29 #ifndef WTF_ASCIICType_h
30 #define WTF_ASCIICType_h 30 #define WTF_ASCIICType_h
31 31
32 #include "wtf/Assertions.h" 32 #include "wtf/Assertions.h"
33 #include "wtf/unicode/Unicode.h"
33 34
34 // The behavior of many of the functions in the <ctype.h> header is dependent 35 // The behavior of many of the functions in the <ctype.h> header is dependent
35 // on the current locale. But in the WebKit project, all uses of those functions 36 // on the current locale. But in the WebKit project, all uses of those functions
36 // are in code processing something that's not locale-specific. These equivalent s 37 // are in code processing something that's not locale-specific. These equivalent s
37 // for some of the <ctype.h> functions are named more explicitly, not dependent 38 // for some of the <ctype.h> functions are named more explicitly, not dependent
38 // on the C library locale, and we should also optimize them as needed. 39 // on the C library locale, and we should also optimize them as needed.
39 40
40 // All functions return false or leave the character unchanged if passed a chara cter 41 // All functions return false or leave the character unchanged if passed a chara cter
41 // that is outside the range 0-7F. So they can be used on Unicode strings or 42 // that is outside the range 0-7F. So they can be used on Unicode strings or
42 // characters if the intent is to do processing only if the character is ASCII. 43 // characters if the intent is to do processing only if the character is ASCII.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 template<typename CharType> inline bool isASCIISpace(CharType c) 100 template<typename CharType> inline bool isASCIISpace(CharType c)
100 { 101 {
101 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); 102 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
102 } 103 }
103 104
104 template<typename CharType> inline bool isASCIIUpper(CharType c) 105 template<typename CharType> inline bool isASCIIUpper(CharType c)
105 { 106 {
106 return c >= 'A' && c <= 'Z'; 107 return c >= 'A' && c <= 'Z';
107 } 108 }
108 109
110 const LChar ASCIICaseFoldTable[256] = {
111 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c , 0x0d, 0x0e, 0x0f,
112 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c , 0x1d, 0x1e, 0x1f,
113 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c , 0x2d, 0x2e, 0x2f,
114 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c , 0x3d, 0x3e, 0x3f,
115 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f,
116 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c , 0x5d, 0x5e, 0x5f,
117 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f,
118 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c , 0x7d, 0x7e, 0x7f,
119 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c , 0x8d, 0x8e, 0x8f,
120 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c , 0x9d, 0x9e, 0x9f,
121 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac , 0xad, 0xae, 0xaf,
122 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc , 0xbd, 0xbe, 0xbf,
123 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc , 0xcd, 0xce, 0xcf,
124 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc , 0xdd, 0xde, 0xdf,
125 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec , 0xed, 0xee, 0xef,
126 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc , 0xfd, 0xfe, 0xff
127 };
128
109 template<typename CharType> inline CharType toASCIILower(CharType c) 129 template<typename CharType> inline CharType toASCIILower(CharType c)
110 { 130 {
111 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER == 170060610 131 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER == 170060610
112 // Make a workaround for VS2012 update 3 optimizer bug, remove once VS2012 f ix it. 132 // Make a workaround for VS2012 update 3 optimizer bug, remove once VS2012 f ix it.
113 return (c >= 'A' && c <= 'Z') ? c + 0x20 : c; 133 return (c >= 'A' && c <= 'Z') ? c + 0x20 : c;
114 #else 134 #else
115 return c | ((c >= 'A' && c <= 'Z') << 5); 135 return c | ((c >= 'A' && c <= 'Z') << 5);
116 #endif 136 #endif
117 } 137 }
118 138
139 inline LChar toASCIILower(LChar c)
140 {
141 return ASCIICaseFoldTable[c];
142 }
143
144 inline char toASCIILower(char c)
145 {
146 return static_cast<char>(ASCIICaseFoldTable[static_cast<LChar>(c)]);
147 }
148
119 template<typename CharType> inline CharType toASCIILowerUnchecked(CharType chara cter) 149 template<typename CharType> inline CharType toASCIILowerUnchecked(CharType chara cter)
120 { 150 {
121 // This function can be used for comparing any input character 151 // This function can be used for comparing any input character
122 // to a lowercase English character. The isASCIIAlphaCaselessEqual 152 // to a lowercase English character. The isASCIIAlphaCaselessEqual
123 // below should be used for regular comparison of ASCII alpha 153 // below should be used for regular comparison of ASCII alpha
124 // characters, but switch statements in CSS tokenizer require 154 // characters, but switch statements in CSS tokenizer require
125 // direct use of this function. 155 // direct use of this function.
126 return character | 0x20; 156 return character | 0x20;
127 } 157 }
128 158
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 using WTF::isASCIIUpper; 207 using WTF::isASCIIUpper;
178 using WTF::toASCIIHexValue; 208 using WTF::toASCIIHexValue;
179 using WTF::toASCIILower; 209 using WTF::toASCIILower;
180 using WTF::toASCIILowerUnchecked; 210 using WTF::toASCIILowerUnchecked;
181 using WTF::toASCIIUpper; 211 using WTF::toASCIIUpper;
182 using WTF::lowerNibbleToASCIIHexDigit; 212 using WTF::lowerNibbleToASCIIHexDigit;
183 using WTF::upperNibbleToASCIIHexDigit; 213 using WTF::upperNibbleToASCIIHexDigit;
184 using WTF::isASCIIAlphaCaselessEqual; 214 using WTF::isASCIIAlphaCaselessEqual;
185 215
186 #endif 216 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/ASCIICTypeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698