From af5efbc1901f8c4906607b1ebf527a200938223b Mon Sep 17 00:00:00 2001 From: "msaboff@apple.com" Date: Sat, 18 Aug 2012 00:43:25 +0000 Subject: [PATCH] Add ability to create AtomicString using LChar* buffer and length https://bugs.webkit.org/show_bug.cgi?id=94381 Reviewed by Geoffrey Garen. Allows the use of 8 bit string data directly without converting to 16 bits first. * wtf/text/AtomicString.cpp: (WTF::LCharBufferTranslator::hash): (LCharBufferTranslator): (WTF::LCharBufferTranslator::equal): (WTF::LCharBufferTranslator::translate): (WTF::AtomicString::add): * wtf/text/AtomicString.h: (WTF::AtomicString::AtomicString): (AtomicString): * wtf/text/StringImpl.h: (StringImpl): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@125958 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WTF/ChangeLog | 21 ++++++++++++++ Source/WTF/wtf/text/AtomicString.cpp | 32 ++++++++++++++++++++++ Source/WTF/wtf/text/AtomicString.h | 2 ++ Source/WTF/wtf/text/StringImpl.h | 2 ++ .../xcshareddata/xcschemes/All Source.xcscheme | 5 ++-- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog index df84e9f..d578c8e 100644 --- a/Source/WTF/ChangeLog +++ b/Source/WTF/ChangeLog @@ -1,3 +1,24 @@ +2012-08-17 Michael Saboff + + Add ability to create AtomicString using LChar* buffer and length + https://bugs.webkit.org/show_bug.cgi?id=94381 + + Reviewed by Geoffrey Garen. + + Allows the use of 8 bit string data directly without converting to 16 bits first. + + * wtf/text/AtomicString.cpp: + (WTF::LCharBufferTranslator::hash): + (LCharBufferTranslator): + (WTF::LCharBufferTranslator::equal): + (WTF::LCharBufferTranslator::translate): + (WTF::AtomicString::add): + * wtf/text/AtomicString.h: + (WTF::AtomicString::AtomicString): + (AtomicString): + * wtf/text/StringImpl.h: + (StringImpl): + 2012-08-17 Benjamin Poulain Make it easier to append a literal to StringBuilder diff --git a/Source/WTF/wtf/text/AtomicString.cpp b/Source/WTF/wtf/text/AtomicString.cpp index a588117..8f14a5f 100644 --- a/Source/WTF/wtf/text/AtomicString.cpp +++ b/Source/WTF/wtf/text/AtomicString.cpp @@ -298,6 +298,26 @@ PassRefPtr AtomicString::add(StringImpl* baseString, unsigned start, SubstringLocation buffer = { baseString, start, length }; return addToStringTable(buffer); } + +typedef HashTranslatorCharBuffer LCharBuffer; +struct LCharBufferTranslator { + static unsigned hash(const LCharBuffer& buf) + { + return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length); + } + + static bool equal(StringImpl* const& str, const LCharBuffer& buf) + { + return WTF::equal(str, buf.s, buf.length); + } + + static void translate(StringImpl*& location, const LCharBuffer& buf, unsigned hash) + { + location = StringImpl::create(buf.s, buf.length).leakRef(); + location->setHash(hash); + location->setIsAtomic(true); + } +}; typedef HashTranslatorCharBuffer CharBuffer; struct CharBufferFromLiteralDataTranslator { @@ -319,6 +339,18 @@ struct CharBufferFromLiteralDataTranslator { } }; +PassRefPtr AtomicString::add(const LChar* s, unsigned length) +{ + if (!s) + return 0; + + if (!length) + return StringImpl::empty(); + + LCharBuffer buffer = { s, length }; + return addToStringTable(buffer); +} + PassRefPtr AtomicString::addFromLiteralData(const char* characters, unsigned length) { ASSERT(characters); diff --git a/Source/WTF/wtf/text/AtomicString.h b/Source/WTF/wtf/text/AtomicString.h index 194d30a..6b89ac8 100644 --- a/Source/WTF/wtf/text/AtomicString.h +++ b/Source/WTF/wtf/text/AtomicString.h @@ -43,6 +43,7 @@ public: AtomicString() { } AtomicString(const LChar* s) : m_string(add(s)) { } AtomicString(const char* s) : m_string(add(s)) { } + AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) { } AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) { } AtomicString(const UChar* s, unsigned length, unsigned existingHash) : m_string(add(s, length, existingHash)) { } AtomicString(const UChar* s) : m_string(add(s)) { } @@ -158,6 +159,7 @@ private: WTF_EXPORT_STRING_API static PassRefPtr add(const LChar*); ALWAYS_INLINE static PassRefPtr add(const char* s) { return add(reinterpret_cast(s)); }; + WTF_EXPORT_STRING_API static PassRefPtr add(const LChar*, unsigned length); WTF_EXPORT_STRING_API static PassRefPtr add(const UChar*, unsigned length); ALWAYS_INLINE static PassRefPtr add(const char* s, unsigned length) { return add(reinterpret_cast(s), length); }; WTF_EXPORT_STRING_API static PassRefPtr add(const UChar*, unsigned length, unsigned existingHash); diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index 2a3ae2b..c6059f8 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -58,6 +58,7 @@ namespace WTF { struct CStringTranslator; template struct HashAndCharactersTranslator; struct HashAndUTF8CharactersTranslator; +struct LCharBufferTranslator; struct CharBufferFromLiteralDataTranslator; struct SubstringTranslator; struct UCharBufferTranslator; @@ -77,6 +78,7 @@ class StringImpl { template friend struct WTF::HashAndCharactersTranslator; friend struct WTF::HashAndUTF8CharactersTranslator; friend struct WTF::CharBufferFromLiteralDataTranslator; + friend struct WTF::LCharBufferTranslator; friend struct WTF::SubstringTranslator; friend struct WTF::UCharBufferTranslator; friend class AtomicStringImpl; diff --git a/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme b/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme index fd2cca7..f7a1785 100644 --- a/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme +++ b/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme @@ -118,13 +118,14 @@ -- 1.8.3.1