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

Side by Side Diff: Source/wtf/text/StringImpl.cpp

Issue 1152163005: Speed up case folding for 8-bit strings (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added a unit test 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 | « Source/wtf/text/StringImpl.h ('k') | Source/wtf/text/StringImplTest.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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved.
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 return charactersToDouble(characters16(), m_length, ok); 1063 return charactersToDouble(characters16(), m_length, ok);
1064 } 1064 }
1065 1065
1066 float StringImpl::toFloat(bool* ok) 1066 float StringImpl::toFloat(bool* ok)
1067 { 1067 {
1068 if (is8Bit()) 1068 if (is8Bit())
1069 return charactersToFloat(characters8(), m_length, ok); 1069 return charactersToFloat(characters8(), m_length, ok);
1070 return charactersToFloat(characters16(), m_length, ok); 1070 return charactersToFloat(characters16(), m_length, ok);
1071 } 1071 }
1072 1072
1073 // Table is based on ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt
1074 const UChar StringImpl::latin1CaseFoldTable[256] = {
1075 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x00 09, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
1076 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x00 19, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
1077 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x00 29, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
1078 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x00 39, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
1079 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x00 69, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
1080 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x00 79, 0x007a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
1081 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x00 69, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
1082 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x00 79, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
1083 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x00 89, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
1084 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x00 99, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
1085 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00 a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
1086 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x03bc, 0x00b6, 0x00b7, 0x00b8, 0x00 b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
1087 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
1088 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00d7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00df,
1089 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
1090 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
1091 };
1092
1073 bool equalIgnoringCase(const LChar* a, const LChar* b, unsigned length) 1093 bool equalIgnoringCase(const LChar* a, const LChar* b, unsigned length)
1074 { 1094 {
1075 while (length--) { 1095 while (length--) {
1076 LChar bc = *b++; 1096 if (StringImpl::latin1CaseFoldTable[*a++] != StringImpl::latin1CaseFoldT able[*b++])
1077 if (foldCase(*a++) != foldCase(bc))
1078 return false; 1097 return false;
1079 } 1098 }
1080 return true; 1099 return true;
1081 } 1100 }
1082 1101
1083 bool equalIgnoringCase(const UChar* a, const LChar* b, unsigned length) 1102 bool equalIgnoringCase(const UChar* a, const LChar* b, unsigned length)
1084 { 1103 {
1085 while (length--) { 1104 while (length--) {
1086 LChar bc = *b++; 1105 if (foldCase(*a++) != StringImpl::latin1CaseFoldTable[*b++])
1087 if (foldCase(*a++) != foldCase(bc))
1088 return false; 1106 return false;
1089 } 1107 }
1090 return true; 1108 return true;
1091 } 1109 }
1092 1110
1093 size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start) 1111 size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start)
1094 { 1112 {
1095 if (is8Bit()) 1113 if (is8Bit())
1096 return WTF::find(characters8(), m_length, matchFunction, start); 1114 return WTF::find(characters8(), m_length, matchFunction, start);
1097 return WTF::find(characters16(), m_length, matchFunction, start); 1115 return WTF::find(characters16(), m_length, matchFunction, start);
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 2106
2089 size_t StringImpl::sizeInBytes() const 2107 size_t StringImpl::sizeInBytes() const
2090 { 2108 {
2091 size_t size = length(); 2109 size_t size = length();
2092 if (!is8Bit()) 2110 if (!is8Bit())
2093 size *= 2; 2111 size *= 2;
2094 return size + sizeof(*this); 2112 return size + sizeof(*this);
2095 } 2113 }
2096 2114
2097 } // namespace WTF 2115 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/text/StringImpl.h ('k') | Source/wtf/text/StringImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698