Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit af5efbc1901f8c4906607b1ebf527a200938223b 1 parent 8586189
msaboff@apple.com authored
View
21 Source/WTF/ChangeLog
@@ -1,3 +1,24 @@
+2012-08-17 Michael Saboff <msaboff@apple.com>
+
+ 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 <bpoulain@apple.com>
Make it easier to append a literal to StringBuilder
View
32 Source/WTF/wtf/text/AtomicString.cpp
@@ -298,6 +298,26 @@ PassRefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start,
SubstringLocation buffer = { baseString, start, length };
return addToStringTable<SubstringLocation, SubstringTranslator>(buffer);
}
+
+typedef HashTranslatorCharBuffer<LChar> 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<char> CharBuffer;
struct CharBufferFromLiteralDataTranslator {
@@ -319,6 +339,18 @@ struct CharBufferFromLiteralDataTranslator {
}
};
+PassRefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length)
+{
+ if (!s)
+ return 0;
+
+ if (!length)
+ return StringImpl::empty();
+
+ LCharBuffer buffer = { s, length };
+ return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer);
+}
+
PassRefPtr<StringImpl> AtomicString::addFromLiteralData(const char* characters, unsigned length)
{
ASSERT(characters);
View
2  Source/WTF/wtf/text/AtomicString.h
@@ -43,6 +43,7 @@ class AtomicString {
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 @@ class AtomicString {
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const LChar*);
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
+ WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const LChar*, unsigned length);
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length);
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const char*>(s), length); };
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
View
2  Source/WTF/wtf/text/StringImpl.h
@@ -58,6 +58,7 @@ namespace WTF {
struct CStringTranslator;
template<typename CharacterType> struct HashAndCharactersTranslator;
struct HashAndUTF8CharactersTranslator;
+struct LCharBufferTranslator;
struct CharBufferFromLiteralDataTranslator;
struct SubstringTranslator;
struct UCharBufferTranslator;
@@ -77,6 +78,7 @@ class StringImpl {
template<typename CharacterType> 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;
View
5 WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme
@@ -118,13 +118,14 @@
</Testables>
</TestAction>
<LaunchAction
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "YES"
debugDocumentVersioning = "YES"
+ enableOpenGLFrameCaptureMode = "0"
allowLocationSimulation = "YES">
<PathRunnable
FilePath = "/Applications/Safari.app/Contents/MacOS/SafariForWebKitDevelopment">
Please sign in to comment.
Something went wrong with that request. Please try again.