Changeset 94475 in webkit for trunk/Source/JavaScriptCore
- Timestamp:
- Sep 2, 2011, 6:08:10 PM (14 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r94470 r94475 1 2011-09-02 Michael Saboff <[email protected]> 2 3 Replace local implementation of string equals() methods with UString versions 4 https://bugs.webkit.org/show_bug.cgi?id=67342 5 6 In preparation to allowing StringImpl to be backed by 8 bit 7 characters when appropriate, we need to eliminate or change the 8 usage of StringImpl::characters(). Change the uses of characters() 9 that are used to implement redundant equals() methods. 10 11 Reviewed by Gavin Barraclough. 12 13 * runtime/Identifier.cpp: 14 (JSC::Identifier::equal): 15 * runtime/Identifier.h: 16 (JSC::Identifier::equal): 17 * wtf/text/AtomicString.cpp: 18 (WTF::CStringTranslator::equal): Moved an optimized method to here. 19 (WTF::operator==): 20 * wtf/text/StringImpl.cpp: 21 (WTF::equal): 22 * wtf/text/StringImpl.h: 23 1 24 2011-09-02 Michael Saboff <[email protected]> 2 25 -
trunk/Source/JavaScriptCore/JavaScriptCore.exp
r94470 r94475 109 109 __ZN3JSC10Identifier4fromEPNS_9ExecStateEi 110 110 __ZN3JSC10Identifier4fromEPNS_9ExecStateEj 111 __ZN3JSC10Identifier5equalEPKN3WTF10StringImplEPKc112 111 __ZN3JSC10Identifier8toUInt32ERKNS_7UStringERb 113 112 __ZN3JSC10JSFunction14finishCreationEPNS_9ExecStateEPNS_14JSGlobalObjectEPNS_18FunctionExecutableEPNS_14ScopeChainNodeE … … 478 477 __ZN3WTF5MutexD1Ev 479 478 __ZN3WTF5equalEPKNS_10StringImplEPKc 479 __ZN3WTF5equalEPKNS_10StringImplEPKtj 480 480 __ZN3WTF5equalEPKNS_10StringImplES2_ 481 481 __ZN3WTF5yieldEv … … 525 525 __ZN3WTF9emptyAtomE 526 526 __ZN3WTF9xmlnsAtomE 527 __ZN3WTFeqERKNS_12AtomicStringEPKc528 __ZN3WTFeqERKNS_12AtomicStringERKNS_6VectorItLm0EEE529 527 __ZN3WTFeqERKNS_7CStringES2_ 530 528 __ZNK3JSC10JSFunction23isHostFunctionNonInlineEv -
trunk/Source/JavaScriptCore/runtime/Identifier.cpp
r94336 r94475 68 68 } 69 69 70 bool Identifier::equal(const StringImpl* r, const char* s)71 {72 int length = r->length();73 const UChar* d = r->characters();74 for (int i = 0; i != length; ++i)75 if (d[i] != (unsigned char)s[i])76 return false;77 return s[length] == 0;78 }79 80 70 struct IdentifierCStringTranslator { 81 71 static unsigned hash(const char* c) -
trunk/Source/JavaScriptCore/runtime/Identifier.h
r88668 r94475 136 136 } 137 137 138 inline bool Identifier::equal(const StringImpl* r, const char* s) 139 { 140 return WTF::equal(r, s); 141 } 142 138 143 inline bool Identifier::equal(const StringImpl* r, const UChar* s, unsigned length) 139 144 { 140 if (r->length() != length) 141 return false; 142 const UChar* d = r->characters(); 143 for (unsigned i = 0; i != length; ++i) 144 if (d[i] != s[i]) 145 return false; 146 return true; 145 return WTF::equal(r, s, length); 147 146 } 148 147 -
trunk/Source/JavaScriptCore/wtf/text/AtomicString.cpp
r89906 r94475 91 91 } 92 92 93 static bool equal(StringImpl* r, const char* s) 94 { 95 int length = r->length(); 96 const UChar* d = r->characters(); 97 for (int i = 0; i != length; ++i) { 98 unsigned char c = s[i]; 99 if (d[i] != c) 100 return false; 101 } 102 return !s[length]; 93 static inline bool equal(StringImpl* r, const char* s) 94 { 95 return WTF::equal(r, s); 103 96 } 104 97 … … 111 104 }; 112 105 113 bool operator==(const AtomicString& a, const char* b)114 {115 StringImpl* impl = a.impl();116 if ((!impl || !impl->characters()) && !b)117 return true;118 if ((!impl || !impl->characters()) || !b)119 return false;120 return CStringTranslator::equal(impl, b);121 }122 123 106 PassRefPtr<StringImpl> AtomicString::add(const char* c) 124 107 { … … 135 118 unsigned length; 136 119 }; 137 138 static inline bool equal(StringImpl* string, const UChar* characters, unsigned length)139 {140 if (string->length() != length)141 return false;142 143 // FIXME: perhaps we should have a more abstract macro that indicates when144 // going 4 bytes at a time is unsafe145 #if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC)146 const UChar* stringCharacters = string->characters();147 for (unsigned i = 0; i != length; ++i) {148 if (*stringCharacters++ != *characters++)149 return false;150 }151 return true;152 #else153 /* Do it 4-bytes-at-a-time on architectures where it's safe */154 155 const uint32_t* stringCharacters = reinterpret_cast<const uint32_t*>(string->characters());156 const uint32_t* bufferCharacters = reinterpret_cast<const uint32_t*>(characters);157 158 unsigned halfLength = length >> 1;159 for (unsigned i = 0; i != halfLength; ++i) {160 if (*stringCharacters++ != *bufferCharacters++)161 return false;162 }163 164 if (length & 1 && *reinterpret_cast<const uint16_t*>(stringCharacters) != *reinterpret_cast<const uint16_t*>(bufferCharacters))165 return false;166 167 return true;168 #endif169 }170 171 bool operator==(const AtomicString& string, const Vector<UChar>& vector)172 {173 return string.impl() && equal(string.impl(), vector.data(), vector.size());174 }175 120 176 121 struct UCharBufferTranslator { -
trunk/Source/JavaScriptCore/wtf/text/AtomicString.h
r89906 r94475 136 136 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); } 137 137 bool operator==(const AtomicString& a, const char* b); 138 bool operator==(const AtomicString& a, const Vector<UChar>& b); 138 inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), b); } 139 inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); } 139 140 inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); } 140 141 inline bool operator==(const char* a, const AtomicString& b) { return b == a; } -
trunk/Source/JavaScriptCore/wtf/text/StringImpl.cpp
r91913 r94475 996 996 } 997 997 998 bool equal(const StringImpl* a, const UChar* b, unsigned length) 999 { 1000 if (!a) 1001 return !b; 1002 if (!b) 1003 return false; 1004 1005 if (a->length() != length) 1006 return false; 1007 // FIXME: perhaps we should have a more abstract macro that indicates when 1008 // going 4 bytes at a time is unsafe 1009 #if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC) 1010 const UChar* as = a->characters(); 1011 for (unsigned i = 0; i != length; ++i) 1012 if (as[i] != b[i]) 1013 return false; 1014 return true; 1015 #else 1016 /* Do it 4-bytes-at-a-time on architectures where it's safe */ 1017 1018 const uint32_t* aCharacters = reinterpret_cast<const uint32_t*>(a->characters()); 1019 const uint32_t* bCharacters = reinterpret_cast<const uint32_t*>(b); 1020 1021 unsigned halfLength = length >> 1; 1022 for (unsigned i = 0; i != halfLength; ++i) { 1023 if (*aCharacters++ != *bCharacters++) 1024 return false; 1025 } 1026 1027 if (length & 1 && *reinterpret_cast<const uint16_t*>(aCharacters) != *reinterpret_cast<const uint16_t*>(bCharacters)) 1028 return false; 1029 1030 return true; 1031 #endif 1032 } 1033 998 1034 bool equalIgnoringCase(StringImpl* a, StringImpl* b) 999 1035 { -
trunk/Source/JavaScriptCore/wtf/text/StringImpl.h
r92569 r94475 348 348 bool equal(const StringImpl*, const char*); 349 349 inline bool equal(const char* a, StringImpl* b) { return equal(b, a); } 350 bool equal(const StringImpl*, const UChar*, unsigned); 350 351 351 352 bool equalIgnoringCase(StringImpl*, StringImpl*);
Note:
See TracChangeset
for help on using the changeset viewer.