- Revision
- 125356
- Author
- [email protected]
- Date
- 2012-08-11 14:12:27 -0700 (Sat, 11 Aug 2012)
Log Message
WebCore::findAtomicString(PropertyName) always convert the name to 16bits
https://bugs.webkit.org/show_bug.cgi?id=93685
Reviewed by Geoffrey Garen.
Source/WebCore:
* bindings/js/JSDOMBinding.cpp:
(WebCore::findAtomicString):
Use the new AtomicString::find() to avoid calling StringImpl::characters().
Source/WTF:
Previously, WebCore::findAtomicString() was causing a conversion for the 8bit property name
to a 16bits due to the call to StringImpl::character16().
This patch fixes the issue by adding support for both 8bits and 16bits string in AtomicString::find().
* wtf/text/AtomicString.cpp:
(HashAndCharacters):
(WTF::HashAndCharactersTranslator::hash):
(WTF::HashAndCharactersTranslator::equal):
(WTF::HashAndCharactersTranslator::translate):
Use a template to make the struct and the translator independant of the CharacterType.
(WTF::AtomicString::add):
(WTF::findString):
(WTF::AtomicString::find): Change the API to take a StringImpl*. AtomicString can use
it efficiently to find the right string.
* wtf/text/AtomicString.h:
(AtomicString):
* wtf/text/StringImpl.h:
(StringImpl): Adapt the friends translator to support the template.
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (125355 => 125356)
--- trunk/Source/WTF/ChangeLog 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WTF/ChangeLog 2012-08-11 21:12:27 UTC (rev 125356)
@@ -1,3 +1,31 @@
+2012-08-11 Benjamin Poulain <[email protected]>
+
+ WebCore::findAtomicString(PropertyName) always convert the name to 16bits
+ https://bugs.webkit.org/show_bug.cgi?id=93685
+
+ Reviewed by Geoffrey Garen.
+
+ Previously, WebCore::findAtomicString() was causing a conversion for the 8bit property name
+ to a 16bits due to the call to StringImpl::character16().
+
+ This patch fixes the issue by adding support for both 8bits and 16bits string in AtomicString::find().
+
+ * wtf/text/AtomicString.cpp:
+ (HashAndCharacters):
+ (WTF::HashAndCharactersTranslator::hash):
+ (WTF::HashAndCharactersTranslator::equal):
+ (WTF::HashAndCharactersTranslator::translate):
+ Use a template to make the struct and the translator independant of the CharacterType.
+
+ (WTF::AtomicString::add):
+ (WTF::findString):
+ (WTF::AtomicString::find): Change the API to take a StringImpl*. AtomicString can use
+ it efficiently to find the right string.
+ * wtf/text/AtomicString.h:
+ (AtomicString):
+ * wtf/text/StringImpl.h:
+ (StringImpl): Adapt the friends translator to support the template.
+
2012-08-10 Benjamin Poulain <[email protected]>
Add support for String initialization from literal to WTFString
Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (125355 => 125356)
--- trunk/Source/WTF/wtf/text/AtomicString.cpp 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp 2012-08-11 21:12:27 UTC (rev 125356)
@@ -140,25 +140,27 @@
}
};
+template<typename CharacterType>
struct HashAndCharacters {
unsigned hash;
- const UChar* characters;
+ const CharacterType* characters;
unsigned length;
};
+template<typename CharacterType>
struct HashAndCharactersTranslator {
- static unsigned hash(const HashAndCharacters& buffer)
+ static unsigned hash(const HashAndCharacters<CharacterType>& buffer)
{
ASSERT(buffer.hash == StringHasher::computeHashAndMaskTop8Bits(buffer.characters, buffer.length));
return buffer.hash;
}
- static bool equal(StringImpl* const& string, const HashAndCharacters& buffer)
+ static bool equal(StringImpl* const& string, const HashAndCharacters<CharacterType>& buffer)
{
return WTF::equal(string, buffer.characters, buffer.length);
}
- static void translate(StringImpl*& location, const HashAndCharacters& buffer, unsigned hash)
+ static void translate(StringImpl*& location, const HashAndCharacters<CharacterType>& buffer, unsigned hash)
{
location = StringImpl::create(buffer.characters, buffer.length).leakRef();
location->setHash(hash);
@@ -233,8 +235,8 @@
if (!length)
return StringImpl::empty();
- HashAndCharacters buffer = { existingHash, s, length };
- return addToStringTable<HashAndCharacters, HashAndCharactersTranslator>(buffer);
+ HashAndCharacters<UChar> buffer = { existingHash, s, length };
+ return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslator<UChar> >(buffer);
}
PassRefPtr<StringImpl> AtomicString::add(const UChar* s)
@@ -337,16 +339,26 @@
return result;
}
-AtomicStringImpl* AtomicString::find(const UChar* s, unsigned length, unsigned existingHash)
+template<typename CharacterType>
+static inline HashSet<StringImpl*>::iterator findString(const StringImpl* stringImpl)
{
- ASSERT(s);
- ASSERT(existingHash);
+ HashAndCharacters<CharacterType> buffer = { stringImpl->existingHash(), stringImpl->getCharacters<CharacterType>(), stringImpl->length() };
+ return stringTable().find<HashAndCharacters<CharacterType>, HashAndCharactersTranslator<CharacterType> >(buffer);
+}
- if (!length)
+AtomicStringImpl* AtomicString::find(const StringImpl* stringImpl)
+{
+ ASSERT(stringImpl);
+ ASSERT(stringImpl->existingHash());
+
+ if (!stringImpl->length())
return static_cast<AtomicStringImpl*>(StringImpl::empty());
- HashAndCharacters buffer = { existingHash, s, length };
- HashSet<StringImpl*>::iterator iterator = stringTable().find<HashAndCharacters, HashAndCharactersTranslator>(buffer);
+ HashSet<StringImpl*>::iterator iterator;
+ if (stringImpl->is8Bit())
+ iterator = findString<LChar>(stringImpl);
+ else
+ iterator = findString<UChar>(stringImpl);
if (iterator == stringTable().end())
return 0;
return static_cast<AtomicStringImpl*>(*iterator);
Modified: trunk/Source/WTF/wtf/text/AtomicString.h (125355 => 125356)
--- trunk/Source/WTF/wtf/text/AtomicString.h 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WTF/wtf/text/AtomicString.h 2012-08-11 21:12:27 UTC (rev 125356)
@@ -79,7 +79,7 @@
AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
- WTF_EXPORT_STRING_API static AtomicStringImpl* find(const UChar*, unsigned length, unsigned existingHash);
+ WTF_EXPORT_STRING_API static AtomicStringImpl* find(const StringImpl*);
operator const String&() const { return m_string; }
const String& string() const { return m_string; };
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (125355 => 125356)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2012-08-11 21:12:27 UTC (rev 125356)
@@ -56,7 +56,7 @@
namespace WTF {
struct CStringTranslator;
-struct HashAndCharactersTranslator;
+template<typename CharacterType> struct HashAndCharactersTranslator;
struct HashAndUTF8CharactersTranslator;
struct CharBufferFromLiteralDataTranslator;
struct SubstringTranslator;
@@ -74,7 +74,7 @@
friend struct JSC::IdentifierCharBufferTranslator<UChar>;
friend struct JSC::IdentifierLCharFromUCharTranslator;
friend struct WTF::CStringTranslator;
- friend struct WTF::HashAndCharactersTranslator;
+ template<typename CharacterType> friend struct WTF::HashAndCharactersTranslator;
friend struct WTF::HashAndUTF8CharactersTranslator;
friend struct WTF::CharBufferFromLiteralDataTranslator;
friend struct WTF::SubstringTranslator;
Modified: trunk/Source/WebCore/ChangeLog (125355 => 125356)
--- trunk/Source/WebCore/ChangeLog 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WebCore/ChangeLog 2012-08-11 21:12:27 UTC (rev 125356)
@@ -1,3 +1,14 @@
+2012-08-11 Benjamin Poulain <[email protected]>
+
+ WebCore::findAtomicString(PropertyName) always convert the name to 16bits
+ https://bugs.webkit.org/show_bug.cgi?id=93685
+
+ Reviewed by Geoffrey Garen.
+
+ * bindings/js/JSDOMBinding.cpp:
+ (WebCore::findAtomicString):
+ Use the new AtomicString::find() to avoid calling StringImpl::characters().
+
2012-08-11 Caio Marcelo de Oliveira Filho <[email protected]>
[Qt] Remove QtSenderStack now we do not support __qt_sender__ anymore in Qt bridge
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (125355 => 125356)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2012-08-11 20:01:53 UTC (rev 125355)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2012-08-11 21:12:27 UTC (rev 125356)
@@ -115,7 +115,7 @@
if (!impl)
return 0;
ASSERT(impl->existingHash());
- return AtomicString::find(impl->characters(), impl->length(), impl->existingHash());
+ return AtomicString::find(impl);
}
String valueToStringWithNullCheck(ExecState* exec, JSValue value)