+2015-05-19 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ Move AtomicStringImpl table related operations from AtomicString to AtomicStringImpl
+ https://bugs.webkit.org/show_bug.cgi?id=145109
+
+ Reviewed by Darin Adler.
+
+ * bytecode/CodeBlock.cpp:
+ (JSC::CodeBlock::nameForRegister):
+ * runtime/Identifier.cpp:
+ (JSC::Identifier::add):
+ (JSC::Identifier::add8):
+ * runtime/Identifier.h:
+ (JSC::Identifier::add):
+ * runtime/IdentifierInlines.h:
+ (JSC::Identifier::Identifier):
+ (JSC::Identifier::add):
+ * runtime/JSString.cpp:
+ (JSC::JSRopeString::resolveRopeToExistingAtomicString):
+ * runtime/JSString.h:
+ (JSC::JSString::toExistingAtomicString):
+ * runtime/SmallStrings.cpp:
+ (JSC::SmallStringsStorage::SmallStringsStorage):
+ * runtime/TypeSet.cpp:
+ (JSC::StructureShape::propertyHash):
+
2015-05-19 Joseph Pecoraro <pecoraro@apple.com>
Web Inspector: Improve Preview for NodeList / array like collections
if (ptr->value.varOffset() == VarOffset(virtualRegister)) {
// FIXME: This won't work from the compilation thread.
// https://bugs.webkit.org/show_bug.cgi?id=115300
- return String(ptr->key);
+ return ptr->key.get();
}
}
if (virtualRegister == thisRegister())
if (!c[1])
return *vm->smallStrings.singleCharacterStringRep(c[0]);
- return *AtomicString::add(c);
+ return *AtomicStringImpl::add(c);
}
Ref<StringImpl> Identifier::add(ExecState* exec, const char* c)
if (!length)
return *StringImpl::empty();
- return *AtomicString::add(s, length);
+ return *AtomicStringImpl::add(s, length);
}
Identifier Identifier::from(ExecState* exec, unsigned value)
if (!length)
return *StringImpl::empty();
- return *AtomicString::add(s, length);
+ return *AtomicStringImpl::add(s, length);
}
inline bool operator==(const Identifier& a, const Identifier& b)
#ifndef NDEBUG
checkCurrentAtomicStringTable(exec);
if (string)
- ASSERT_WITH_MESSAGE(!string->length() || string->isSymbol() || AtomicString::isInAtomicStringTable(string), "The atomic string comes from an other thread!");
+ ASSERT_WITH_MESSAGE(!string->length() || string->isSymbol() || AtomicStringImpl::isInAtomicStringTable(string), "The atomic string comes from an other thread!");
#else
UNUSED_PARAM(exec);
#endif
#ifndef NDEBUG
checkCurrentAtomicStringTable(exec);
if (!string.isNull())
- ASSERT_WITH_MESSAGE(!string.length() || string.impl()->isSymbol() || AtomicString::isInAtomicStringTable(string.impl()), "The atomic string comes from an other thread!");
+ ASSERT_WITH_MESSAGE(!string.length() || string.impl()->isSymbol() || AtomicStringImpl::isInAtomicStringTable(string.impl()), "The atomic string comes from an other thread!");
#else
UNUSED_PARAM(exec);
#endif
#ifndef NDEBUG
checkCurrentAtomicStringTable(exec);
#endif
- return *AtomicString::addWithStringTableProvider(*exec, r);
+ return *AtomicStringImpl::addWithStringTableProvider(*exec, r);
}
inline Ref<StringImpl> Identifier::add(VM* vm, StringImpl* r)
{
#ifndef NDEBUG
checkCurrentAtomicStringTable(vm);
#endif
- return *AtomicString::addWithStringTableProvider(*vm, r);
+ return *AtomicStringImpl::addWithStringTableProvider(*vm, r);
}
inline Identifier Identifier::fromUid(VM* vm, StringImpl* uid)
{
if (m_length > maxLengthForOnStackResolve) {
resolveRope(exec);
- if (AtomicStringImpl* existingAtomicString = AtomicString::find(m_value.impl())) {
+ if (AtomicStringImpl* existingAtomicString = AtomicStringImpl::lookUp(m_value.impl())) {
m_value = *existingAtomicString;
setIs8Bit(m_value.impl()->is8Bit());
clearFibers();
if (is8Bit()) {
LChar buffer[maxLengthForOnStackResolve];
resolveRopeInternal8(buffer);
- if (AtomicStringImpl* existingAtomicString = AtomicString::find(buffer, m_length)) {
+ if (AtomicStringImpl* existingAtomicString = AtomicStringImpl::lookUp(buffer, m_length)) {
m_value = *existingAtomicString;
setIs8Bit(m_value.impl()->is8Bit());
clearFibers();
} else {
UChar buffer[maxLengthForOnStackResolve];
resolveRopeInternal16(buffer);
- if (AtomicStringImpl* existingAtomicString = AtomicString::find(buffer, m_length)) {
+ if (AtomicStringImpl* existingAtomicString = AtomicStringImpl::lookUp(buffer, m_length)) {
m_value = *existingAtomicString;
setIs8Bit(m_value.impl()->is8Bit());
clearFibers();
return static_cast<const JSRopeString*>(this)->resolveRopeToExistingAtomicString(exec);
if (m_value.impl()->isAtomic())
return static_cast<AtomicStringImpl*>(m_value.impl());
- return AtomicString::find(m_value.impl());
+ return AtomicStringImpl::lookUp(m_value.impl());
}
inline const String& JSString::value(ExecState* exec) const
RefPtr<StringImpl> baseString = StringImpl::createUninitialized(singleCharacterStringCount, characterBuffer);
for (unsigned i = 0; i < singleCharacterStringCount; ++i) {
characterBuffer[i] = i;
- m_reps[i] = AtomicString::add(PassRefPtr<StringImpl>(StringImpl::createSubstringSharingImpl(baseString, i, 1)).get());
+ m_reps[i] = AtomicStringImpl::add(PassRefPtr<StringImpl>(StringImpl::createSubstringSharingImpl(baseString, i, 1)).get());
}
}
builder.append(':');
for (auto iter = m_fields.begin(), end = m_fields.end(); iter != end; ++iter) {
- String property = String((*iter));
+ String property = iter->get();
property.replace(":", "\\:"); // Ensure that hash({"foo:", "bar"}) != hash({"foo", ":bar"}) because we're using colons as a separator and colons are legal characters in field names in JS.
builder.append(property);
}
+2015-05-19 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ Move AtomicStringImpl table related operations from AtomicString to AtomicStringImpl
+ https://bugs.webkit.org/show_bug.cgi?id=145109
+
+ Reviewed by Darin Adler.
+
+ Now AtomicStringImpl table operations are located in AtomicString.
+ But they should be under AtomicStringImpl.
+ This patch simply moves these operations to AtomicStringImpl.
+
+ And this patch renames static AtomicString::find to static AtomicStringImpl::lookUp
+ because it conflicts with AtomicStringImpl's member function name.
+
+ * WTF.vcxproj/WTF.vcxproj:
+ * WTF.vcxproj/WTF.vcxproj.filters:
+ * WTF.vcxproj/copy-files.cmd:
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ * wtf/PlatformMac.cmake:
+ * wtf/PlatformWin.cmake:
+ * wtf/text/AtomicString.cpp:
+ (WTF::AtomicString::lower):
+ (WTF::AtomicString::convertToASCIILowercase):
+ (WTF::AtomicString::fromUTF8Internal):
+ (WTF::AtomicStringTableLocker::AtomicStringTableLocker): Deleted.
+ (WTF::stringTable): Deleted.
+ (WTF::addToStringTable): Deleted.
+ (WTF::CStringTranslator::hash): Deleted.
+ (WTF::CStringTranslator::equal): Deleted.
+ (WTF::CStringTranslator::translate): Deleted.
+ (WTF::AtomicString::add): Deleted.
+ (WTF::UCharBufferTranslator::hash): Deleted.
+ (WTF::UCharBufferTranslator::equal): Deleted.
+ (WTF::UCharBufferTranslator::translate): Deleted.
+ (WTF::HashAndCharactersTranslator::hash): Deleted.
+ (WTF::HashAndCharactersTranslator::equal): Deleted.
+ (WTF::HashAndCharactersTranslator::translate): Deleted.
+ (WTF::HashAndUTF8CharactersTranslator::hash): Deleted.
+ (WTF::HashAndUTF8CharactersTranslator::equal): Deleted.
+ (WTF::HashAndUTF8CharactersTranslator::translate): Deleted.
+ (WTF::SubstringTranslator::translate): Deleted.
+ (WTF::SubstringTranslator8::hash): Deleted.
+ (WTF::SubstringTranslator8::equal): Deleted.
+ (WTF::SubstringTranslator16::hash): Deleted.
+ (WTF::SubstringTranslator16::equal): Deleted.
+ (WTF::LCharBufferTranslator::hash): Deleted.
+ (WTF::LCharBufferTranslator::equal): Deleted.
+ (WTF::LCharBufferTranslator::translate): Deleted.
+ (WTF::CharBufferFromLiteralDataTranslator::hash): Deleted.
+ (WTF::CharBufferFromLiteralDataTranslator::equal): Deleted.
+ (WTF::CharBufferFromLiteralDataTranslator::translate): Deleted.
+ (WTF::AtomicString::addFromLiteralData): Deleted.
+ (WTF::AtomicString::addSlowCase): Deleted.
+ (WTF::AtomicString::remove): Deleted.
+ (WTF::AtomicString::findSlowCase): Deleted.
+ (WTF::AtomicString::findInternal): Deleted.
+ (WTF::AtomicString::isInAtomicStringTable): Deleted.
+ * wtf/text/AtomicString.h:
+ (WTF::AtomicString::AtomicString):
+ (WTF::AtomicString::fromUTF8):
+ (WTF::AtomicString::find): Deleted.
+ (WTF::AtomicString::add): Deleted.
+ (WTF::AtomicString::addWithStringTableProvider): Deleted.
+ * wtf/text/AtomicStringImpl.cpp: Copied from Source/WTF/wtf/text/AtomicString.cpp.
+ (WTF::AtomicStringTableLocker::AtomicStringTableLocker):
+ (WTF::stringTable):
+ (WTF::addToStringTable):
+ (WTF::CStringTranslator::hash):
+ (WTF::CStringTranslator::equal):
+ (WTF::CStringTranslator::translate):
+ (WTF::AtomicStringImpl::add):
+ (WTF::UCharBufferTranslator::hash):
+ (WTF::UCharBufferTranslator::equal):
+ (WTF::UCharBufferTranslator::translate):
+ (WTF::HashAndCharactersTranslator::hash):
+ (WTF::HashAndCharactersTranslator::equal):
+ (WTF::HashAndCharactersTranslator::translate):
+ (WTF::HashAndUTF8CharactersTranslator::hash):
+ (WTF::HashAndUTF8CharactersTranslator::equal):
+ (WTF::HashAndUTF8CharactersTranslator::translate):
+ (WTF::SubstringTranslator::translate):
+ (WTF::SubstringTranslator8::hash):
+ (WTF::SubstringTranslator8::equal):
+ (WTF::SubstringTranslator16::hash):
+ (WTF::SubstringTranslator16::equal):
+ (WTF::LCharBufferTranslator::hash):
+ (WTF::LCharBufferTranslator::equal):
+ (WTF::LCharBufferTranslator::translate):
+ (WTF::CharBufferFromLiteralDataTranslator::hash):
+ (WTF::CharBufferFromLiteralDataTranslator::equal):
+ (WTF::CharBufferFromLiteralDataTranslator::translate):
+ (WTF::AtomicStringImpl::addLiteral):
+ (WTF::AtomicStringImpl::addSlowCase):
+ (WTF::AtomicStringImpl::remove):
+ (WTF::AtomicStringImpl::lookUpSlowCase):
+ (WTF::AtomicStringImpl::addUTF8):
+ (WTF::AtomicStringImpl::lookUpInternal):
+ (WTF::AtomicStringImpl::isInAtomicStringTable):
+ * wtf/text/AtomicStringImpl.h:
+ (WTF::AtomicStringImpl::lookUp):
+ (WTF::AtomicStringImpl::add):
+ (WTF::AtomicStringImpl::addWithStringTableProvider):
+ (WTF::AtomicStringImpl::AtomicStringImpl): Deleted.
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::~StringImpl):
+ * wtf/text/StringImpl.h:
+ * wtf/text/WTFString.h:
+ (WTF::String::String):
+ * wtf/text/cf/AtomicStringCF.cpp:
+ (WTF::AtomicString::add): Deleted.
+ * wtf/text/cf/AtomicStringImplCF.cpp: Renamed from Source/WTF/wtf/text/cf/AtomicStringCF.cpp.
+ (WTF::AtomicStringImpl::add):
+
2015-05-19 Ting-Wei Lan <lantw44@gmail.com>
[SOUP] Use st_birthtime to get creation time of files on systems support it
<ClCompile Include="..\wtf\StackBounds.cpp" />
<ClCompile Include="..\wtf\StringPrintStream.cpp" />
<ClCompile Include="..\wtf\text\AtomicString.cpp" />
+ <ClCompile Include="..\wtf\text\AtomicStringImpl.cpp" />
<ClCompile Include="..\wtf\text\AtomicStringTable.cpp" />
<ClCompile Include="..\wtf\text\Base64.cpp" />
<ClCompile Include="..\wtf\text\CString.cpp" />
<ClCompile Include="..\wtf\text\StringView.cpp" />
<ClCompile Include="..\wtf\text\SymbolRegistry.cpp" />
<ClCompile Include="..\wtf\text\WTFString.cpp" />
- <ClCompile Include="..\wtf\text\cf\AtomicStringCF.cpp" />
+ <ClCompile Include="..\wtf\text\cf\AtomicStringImplCF.cpp" />
<ClCompile Include="..\wtf\text\cf\StringCF.cpp" />
<ClCompile Include="..\wtf\text\cf\StringImplCF.cpp" />
<ClCompile Include="..\wtf\text\cf\StringViewCF.cpp" />
<ClCompile Include="..\wtf\text\AtomicString.cpp">
<Filter>text</Filter>
</ClCompile>
+ <ClCompile Include="..\wtf\text\AtomicStringImpl.cpp">
+ <Filter>text</Filter>
+ </ClCompile>
<ClCompile Include="..\wtf\text\Base64.cpp">
<Filter>text</Filter>
</ClCompile>
<ClCompile Include="..\wtf\text\WTFString.cpp">
<Filter>text</Filter>
</ClCompile>
- <ClCompile Include="..\wtf\text\cf\AtomicStringCF.cpp">
+ <ClCompile Include="..\wtf\text\cf\AtomicStringImplCF.cpp">
<Filter>text</Filter>
</ClCompile>
<ClCompile Include="..\wtf\text\cf\StringCF.cpp">
for %%f in (\r
..\JavaScriptCore\create_hash_table\r
wtf\text\AtomicString.cpp\r
+ wtf\text\AtomicStringImpl.cpp\r
wtf\text\StringBuilder.cpp\r
wtf\text\StringImpl.cpp\r
wtf\text\WTFString.cpp\r
430B47891AAAAC1A001223DA /* StringCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 430B47871AAAAC1A001223DA /* StringCommon.h */; };
70A993FE1AD7151300FA615B /* SymbolRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */; };
70A993FF1AD7151300FA615B /* SymbolRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 70A993FD1AD7151300FA615B /* SymbolRegistry.h */; };
+ 70ECA60D1B02426800449739 /* AtomicStringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 70ECA60A1B02426800449739 /* AtomicStringImpl.cpp */; };
7CBBA07419BB7FDC00BBF025 /* OSObjectPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */; };
7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */; };
7CDD7FFA186D2A54007433CD /* IteratorRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF9186D2A54007433CD /* IteratorRange.h */; };
9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */; };
A5BA15F3182433A900A82E69 /* StringMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F2182433A900A82E69 /* StringMac.mm */; };
A5BA15F51824348000A82E69 /* StringImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F41824348000A82E69 /* StringImplMac.mm */; };
- A5BA15FA182435A600A82E69 /* AtomicStringCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F7182435A600A82E69 /* AtomicStringCF.cpp */; };
+ A5BA15FA182435A600A82E69 /* AtomicStringImplCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F7182435A600A82E69 /* AtomicStringImplCF.cpp */; };
A5BA15FB182435A600A82E69 /* StringCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F8182435A600A82E69 /* StringCF.cpp */; };
A5BA15FC182435A600A82E69 /* StringImplCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F9182435A600A82E69 /* StringImplCF.cpp */; };
A70DA0841799F04D00529A9B /* Insertion.h in Headers */ = {isa = PBXBuildFile; fileRef = A70DA0821799F04D00529A9B /* Insertion.h */; };
6541CAF41630DB26006D0DEC /* CopyWTFHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyWTFHeaders.xcconfig; sourceTree = "<group>"; };
70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SymbolRegistry.cpp; sourceTree = "<group>"; };
70A993FD1AD7151300FA615B /* SymbolRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SymbolRegistry.h; sourceTree = "<group>"; };
+ 70ECA60A1B02426800449739 /* AtomicStringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringImpl.cpp; sourceTree = "<group>"; };
7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSObjectPtr.h; sourceTree = "<group>"; };
7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorAdaptors.h; sourceTree = "<group>"; };
7CDD7FF9186D2A54007433CD /* IteratorRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorRange.h; sourceTree = "<group>"; };
9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicStringTable.h; sourceTree = "<group>"; };
A5BA15F2182433A900A82E69 /* StringMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringMac.mm; path = mac/StringMac.mm; sourceTree = "<group>"; };
A5BA15F41824348000A82E69 /* StringImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringImplMac.mm; path = mac/StringImplMac.mm; sourceTree = "<group>"; };
- A5BA15F7182435A600A82E69 /* AtomicStringCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicStringCF.cpp; path = cf/AtomicStringCF.cpp; sourceTree = "<group>"; };
+ A5BA15F7182435A600A82E69 /* AtomicStringImplCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicStringImplCF.cpp; path = cf/AtomicStringImplCF.cpp; sourceTree = "<group>"; };
A5BA15F8182435A600A82E69 /* StringCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringCF.cpp; path = cf/StringCF.cpp; sourceTree = "<group>"; };
A5BA15F9182435A600A82E69 /* StringImplCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImplCF.cpp; path = cf/StringImplCF.cpp; sourceTree = "<group>"; };
A70DA0821799F04D00529A9B /* Insertion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Insertion.h; sourceTree = "<group>"; };
A5BA15F61824359E00A82E69 /* cf */ = {
isa = PBXGroup;
children = (
- A5BA15F7182435A600A82E69 /* AtomicStringCF.cpp */,
+ A5BA15F7182435A600A82E69 /* AtomicStringImplCF.cpp */,
A5BA15F8182435A600A82E69 /* StringCF.cpp */,
A5BA15F9182435A600A82E69 /* StringImplCF.cpp */,
93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */,
A8A4731D151A825B004123FF /* AtomicString.cpp */,
A8A4731E151A825B004123FF /* AtomicString.h */,
A8A4731F151A825B004123FF /* AtomicStringHash.h */,
+ 70ECA60A1B02426800449739 /* AtomicStringImpl.cpp */,
A8A47320151A825B004123FF /* AtomicStringImpl.h */,
9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */,
9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */,
E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */,
A8A473B3151A825B004123FF /* fast-dtoa.cc in Sources */,
A8A473C3151A825B004123FF /* FastMalloc.cpp in Sources */,
- A5BA15FA182435A600A82E69 /* AtomicStringCF.cpp in Sources */,
+ A5BA15FA182435A600A82E69 /* AtomicStringImplCF.cpp in Sources */,
E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */,
0F9D3360165DBA73005AD387 /* FilePrintStream.cpp in Sources */,
A8A473B5151A825B004123FF /* fixed-dtoa.cc in Sources */,
A748745217A0BDAE00FA04CB /* SixCharacterHash.cpp in Sources */,
A8A47425151A825B004123FF /* SizeLimits.cpp in Sources */,
A8A47427151A825B004123FF /* StackBounds.cpp in Sources */,
+ 70ECA60D1B02426800449739 /* AtomicStringImpl.cpp in Sources */,
FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */,
A8A4743C151A825B004123FF /* StringBuilder.cpp in Sources */,
A8A47440151A825B004123FF /* StringImpl.cpp in Sources */,
dtoa/strtod.cc
text/AtomicString.cpp
+ text/AtomicStringImpl.cpp
text/AtomicStringTable.cpp
text/Base64.cpp
text/CString.cpp
mac/DeprecatedSymbolsUsedBySafari.mm
mac/MainThreadMac.mm
- text/cf/AtomicStringCF.cpp
+ text/cf/AtomicStringImplCF.cpp
text/cf/StringCF.cpp
text/cf/StringImplCF.cpp
text/cf/StringViewCF.cpp
list(APPEND WTF_SOURCES
- text/cf/AtomicStringCF.cpp
+ text/cf/AtomicStringImplCF.cpp
text/cf/StringCF.cpp
text/cf/StringImplCF.cpp
text/cf/StringViewCF.cpp
#include "config.h"
#include "AtomicString.h"
-#include "AtomicStringTable.h"
-#include "HashSet.h"
#include "IntegerToStringConversion.h"
-#include "StringHash.h"
-#include "Threading.h"
-#include "WTFThreadData.h"
#include "dtoa.h"
-#include <wtf/unicode/UTF8.h>
#if USE(WEB_THREAD)
#include "SpinLock.h"
namespace WTF {
-using namespace Unicode;
-
-static_assert(sizeof(AtomicString) == sizeof(String), "AtomicString and String must be same size!");
-
-#if USE(WEB_THREAD)
-
-class AtomicStringTableLocker : public SpinLockHolder {
- WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
-
- static StaticSpinLock s_stringTableLock;
-public:
- AtomicStringTableLocker()
- : SpinLockHolder(&s_stringTableLock)
- {
- }
-};
-
-StaticSpinLock AtomicStringTableLocker::s_stringTableLock;
-
-#else
-
-class AtomicStringTableLocker {
- WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
-public:
- AtomicStringTableLocker() { }
-};
-
-#endif // USE(WEB_THREAD)
-
-static ALWAYS_INLINE HashSet<StringImpl*>& stringTable()
-{
- return wtfThreadData().atomicStringTable()->table();
-}
-
-template<typename T, typename HashTranslator>
-static inline Ref<StringImpl> addToStringTable(const T& value)
-{
- AtomicStringTableLocker locker;
-
- HashSet<StringImpl*>::AddResult addResult = stringTable().add<HashTranslator>(value);
-
- // If the string is newly-translated, then we need to adopt it.
- // The boolean in the pair tells us if that is so.
- if (addResult.isNewEntry)
- return adoptRef(**addResult.iterator);
- return **addResult.iterator;
-}
-
-struct CStringTranslator {
- static unsigned hash(const LChar* c)
- {
- return StringHasher::computeHashAndMaskTop8Bits(c);
- }
-
- static inline bool equal(StringImpl* r, const LChar* s)
- {
- return WTF::equal(r, s);
- }
-
- static void translate(StringImpl*& location, const LChar* const& c, unsigned hash)
- {
- location = &StringImpl::create(c).leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-RefPtr<StringImpl> AtomicString::add(const LChar* c)
-{
- if (!c)
- return nullptr;
- if (!*c)
- return StringImpl::empty();
-
- return addToStringTable<const LChar*, CStringTranslator>(c);
-}
-
-template<typename CharacterType>
-struct HashTranslatorCharBuffer {
- const CharacterType* s;
- unsigned length;
-};
-
-typedef HashTranslatorCharBuffer<UChar> UCharBuffer;
-struct UCharBufferTranslator {
- static unsigned hash(const UCharBuffer& buf)
- {
- return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length);
- }
-
- static bool equal(StringImpl* const& str, const UCharBuffer& buf)
- {
- return WTF::equal(str, buf.s, buf.length);
- }
-
- static void translate(StringImpl*& location, const UCharBuffer& buf, unsigned hash)
- {
- location = &StringImpl::create8BitIfPossible(buf.s, buf.length).leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-template<typename CharacterType>
-struct HashAndCharacters {
- unsigned hash;
- const CharacterType* characters;
- unsigned length;
-};
-
-template<typename CharacterType>
-struct HashAndCharactersTranslator {
- 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<CharacterType>& buffer)
- {
- return WTF::equal(string, buffer.characters, buffer.length);
- }
-
- static void translate(StringImpl*& location, const HashAndCharacters<CharacterType>& buffer, unsigned hash)
- {
- location = &StringImpl::create(buffer.characters, buffer.length).leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-struct HashAndUTF8Characters {
- unsigned hash;
- const char* characters;
- unsigned length;
- unsigned utf16Length;
-};
-
-struct HashAndUTF8CharactersTranslator {
- static unsigned hash(const HashAndUTF8Characters& buffer)
- {
- return buffer.hash;
- }
-
- static bool equal(StringImpl* const& string, const HashAndUTF8Characters& buffer)
- {
- if (buffer.utf16Length != string->length())
- return false;
-
- // If buffer contains only ASCII characters UTF-8 and UTF16 length are the same.
- if (buffer.utf16Length != buffer.length) {
- if (string->is8Bit())
- return equalLatin1WithUTF8(string->characters8(), buffer.characters, buffer.characters + buffer.length);
-
- return equalUTF16WithUTF8(string->characters16(), buffer.characters, buffer.characters + buffer.length);
- }
-
- if (string->is8Bit()) {
- const LChar* stringCharacters = string->characters8();
-
- for (unsigned i = 0; i < buffer.length; ++i) {
- ASSERT(isASCII(buffer.characters[i]));
- if (stringCharacters[i] != buffer.characters[i])
- return false;
- }
-
- return true;
- }
-
- const UChar* stringCharacters = string->characters16();
-
- for (unsigned i = 0; i < buffer.length; ++i) {
- ASSERT(isASCII(buffer.characters[i]));
- if (stringCharacters[i] != buffer.characters[i])
- return false;
- }
-
- return true;
- }
-
- static void translate(StringImpl*& location, const HashAndUTF8Characters& buffer, unsigned hash)
- {
- UChar* target;
- RefPtr<StringImpl> newString = StringImpl::createUninitialized(buffer.utf16Length, target);
-
- bool isAllASCII;
- const char* source = buffer.characters;
- if (convertUTF8ToUTF16(&source, source + buffer.length, &target, target + buffer.utf16Length, &isAllASCII) != conversionOK)
- ASSERT_NOT_REACHED();
-
- if (isAllASCII)
- newString = StringImpl::create(buffer.characters, buffer.length);
-
- location = newString.release().leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-RefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length)
-{
- if (!s)
- return nullptr;
-
- if (!length)
- return StringImpl::empty();
-
- UCharBuffer buffer = { s, length };
- return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
-}
-
-Ref<StringImpl> AtomicString::add(const UChar* s, unsigned length, unsigned existingHash)
-{
- ASSERT(s);
- ASSERT(existingHash);
-
- if (!length)
- return *StringImpl::empty();
-
- HashAndCharacters<UChar> buffer = { existingHash, s, length };
- return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslator<UChar>>(buffer);
-}
-
-RefPtr<StringImpl> AtomicString::add(const UChar* s)
-{
- if (!s)
- return nullptr;
-
- unsigned length = 0;
- while (s[length] != UChar(0))
- ++length;
-
- if (!length)
- return StringImpl::empty();
-
- UCharBuffer buffer = { s, length };
- return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
-}
-
-struct SubstringLocation {
- StringImpl* baseString;
- unsigned start;
- unsigned length;
-};
-
-struct SubstringTranslator {
- static void translate(StringImpl*& location, const SubstringLocation& buffer, unsigned hash)
- {
- location = &StringImpl::createSubstringSharingImpl(buffer.baseString, buffer.start, buffer.length).leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-struct SubstringTranslator8 : SubstringTranslator {
- static unsigned hash(const SubstringLocation& buffer)
- {
- return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters8() + buffer.start, buffer.length);
- }
-
- static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
- {
- return WTF::equal(string, buffer.baseString->characters8() + buffer.start, buffer.length);
- }
-};
-
-struct SubstringTranslator16 : SubstringTranslator {
- static unsigned hash(const SubstringLocation& buffer)
- {
- return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters16() + buffer.start, buffer.length);
- }
-
- static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
- {
- return WTF::equal(string, buffer.baseString->characters16() + buffer.start, buffer.length);
- }
-};
-
-RefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start, unsigned length)
-{
- if (!baseString)
- return nullptr;
-
- if (!length || start >= baseString->length())
- return StringImpl::empty();
-
- unsigned maxLength = baseString->length() - start;
- if (length >= maxLength) {
- if (!start)
- return add(baseString);
- length = maxLength;
- }
-
- SubstringLocation buffer = { baseString, start, length };
- if (baseString->is8Bit())
- return addToStringTable<SubstringLocation, SubstringTranslator8>(buffer);
- return addToStringTable<SubstringLocation, SubstringTranslator16>(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 {
- static unsigned hash(const CharBuffer& buf)
- {
- return StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const LChar*>(buf.s), buf.length);
- }
-
- static bool equal(StringImpl* const& str, const CharBuffer& buf)
- {
- return WTF::equal(str, buf.s, buf.length);
- }
-
- static void translate(StringImpl*& location, const CharBuffer& buf, unsigned hash)
- {
- location = &StringImpl::createFromLiteral(buf.s, buf.length).leakRef();
- location->setHash(hash);
- location->setIsAtomic(true);
- }
-};
-
-RefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length)
-{
- if (!s)
- return nullptr;
-
- if (!length)
- return StringImpl::empty();
-
- LCharBuffer buffer = { s, length };
- return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer);
-}
-
-Ref<StringImpl> AtomicString::addFromLiteralData(const char* characters, unsigned length)
-{
- ASSERT(characters);
- ASSERT(length);
-
- CharBuffer buffer = { characters, length };
- return addToStringTable<CharBuffer, CharBufferFromLiteralDataTranslator>(buffer);
-}
-
-Ref<StringImpl> AtomicString::addSlowCase(StringImpl& string)
-{
- if (!string.length())
- return *StringImpl::empty();
-
- if (string.isSymbol()) {
- if (string.is8Bit())
- return *add(string.characters8(), string.length());
- return *add(string.characters16(), string.length());
- }
-
- ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicString should not hit the slow case if the string is already atomic.");
-
- AtomicStringTableLocker locker;
- auto addResult = stringTable().add(&string);
-
- if (addResult.isNewEntry) {
- ASSERT(*addResult.iterator == &string);
- string.setIsAtomic(true);
- }
-
- return **addResult.iterator;
-}
-
-Ref<StringImpl> AtomicString::addSlowCase(AtomicStringTable& stringTable, StringImpl& string)
-{
- if (!string.length())
- return *StringImpl::empty();
-
- if (string.isSymbol()) {
- if (string.is8Bit())
- return *add(string.characters8(), string.length());
- return *add(string.characters16(), string.length());
- }
-
- ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicString should not hit the slow case if the string is already atomic.");
-
- AtomicStringTableLocker locker;
- auto addResult = stringTable.table().add(&string);
-
- if (addResult.isNewEntry) {
- ASSERT(*addResult.iterator == &string);
- string.setIsAtomic(true);
- }
-
- return **addResult.iterator;
-}
-
-void AtomicString::remove(StringImpl* string)
-{
- ASSERT(string->isAtomic());
- AtomicStringTableLocker locker;
- HashSet<StringImpl*>& atomicStringTable = stringTable();
- HashSet<StringImpl*>::iterator iterator = atomicStringTable.find(string);
- ASSERT_WITH_MESSAGE(iterator != atomicStringTable.end(), "The string being removed is atomic in the string table of an other thread!");
- atomicStringTable.remove(iterator);
-}
-
AtomicString AtomicString::lower() const
{
// Note: This is a hot function in the Dromaeo benchmark.
return *this;
AtomicString result;
- result.m_string = addSlowCase(*lowercasedString);
+ result.m_string = AtomicStringImpl::add(lowercasedString.get());
return result;
}
return *this;
AtomicString result;
- result.m_string = addSlowCase(*convertedString);
+ result.m_string = AtomicStringImpl::add(convertedString.get());
return result;
}
-AtomicStringImpl* AtomicString::findSlowCase(StringImpl& string)
-{
- ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicStringImpls should return from the fast case.");
-
- if (!string.length())
- return static_cast<AtomicStringImpl*>(StringImpl::empty());
-
- if (string.isSymbol()) {
- if (string.is8Bit())
- return findInternal(string.characters8(), string.length());
- return findInternal(string.characters16(), string.length());
- }
-
- AtomicStringTableLocker locker;
- HashSet<StringImpl*>& atomicStringTable = stringTable();
- auto iterator = atomicStringTable.find(&string);
- if (iterator != atomicStringTable.end())
- return static_cast<AtomicStringImpl*>(*iterator);
- return nullptr;
-}
-
-AtomicString AtomicString::fromUTF8Internal(const char* charactersStart, const char* charactersEnd)
-{
- HashAndUTF8Characters buffer;
- buffer.characters = charactersStart;
- buffer.hash = calculateStringHashAndLengthFromUTF8MaskingTop8Bits(charactersStart, charactersEnd, buffer.length, buffer.utf16Length);
-
- if (!buffer.hash)
- return nullAtom;
-
- AtomicString atomicString;
- atomicString.m_string = addToStringTable<HashAndUTF8Characters, HashAndUTF8CharactersTranslator>(buffer);
- return atomicString;
-}
-
AtomicString AtomicString::number(int number)
{
return numberToStringSigned<AtomicString>(number);
return String(numberToFixedPrecisionString(number, 6, buffer, true));
}
-AtomicStringImpl* AtomicString::findInternal(const LChar* characters, unsigned length)
-{
- AtomicStringTableLocker locker;
- auto& table = stringTable();
-
- LCharBuffer buffer = { characters, length };
- auto iterator = table.find<LCharBufferTranslator>(buffer);
- if (iterator != table.end())
- return static_cast<AtomicStringImpl*>(*iterator);
- return nullptr;
-}
-
-AtomicStringImpl* AtomicString::findInternal(const UChar* characters, unsigned length)
-{
- AtomicStringTableLocker locker;
- auto& table = stringTable();
-
- UCharBuffer buffer = { characters, length };
- auto iterator = table.find<UCharBufferTranslator>(buffer);
- if (iterator != table.end())
- return static_cast<AtomicStringImpl*>(*iterator);
- return nullptr;
-}
-
-#if !ASSERT_DISABLED
-bool AtomicString::isInAtomicStringTable(StringImpl* string)
+AtomicString AtomicString::fromUTF8Internal(const char* charactersStart, const char* charactersEnd)
{
- AtomicStringTableLocker locker;
- return stringTable().contains(string);
+ auto impl = AtomicStringImpl::addUTF8(charactersStart, charactersEnd);
+ if (!impl)
+ return nullAtom;
+ return impl.get();
}
-#endif
#ifndef NDEBUG
void AtomicString::show() const
namespace WTF {
-class AtomicStringTable;
struct AtomicStringHash;
class AtomicString {
public:
WTF_EXPORT_PRIVATE static void init();
- 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)) { }
+ AtomicString();
+ AtomicString(const LChar*);
+ AtomicString(const char*);
+ AtomicString(const LChar*, unsigned length);
+ AtomicString(const UChar*, unsigned length);
+ AtomicString(const UChar*, unsigned length, unsigned existingHash);
+ AtomicString(const UChar*);
template<size_t inlineCapacity>
explicit AtomicString(const Vector<UChar, inlineCapacity>& characters)
- : m_string(add(characters.data(), characters.size()))
+ : m_string(AtomicStringImpl::add(characters.data(), characters.size()))
{
}
- ATOMICSTRING_CONVERSION AtomicString(StringImpl* imp) : m_string(add(imp)) { }
- AtomicString(AtomicStringImpl* imp) : m_string(imp) { }
- ATOMICSTRING_CONVERSION AtomicString(const String& s) : m_string(add(s.impl())) { }
- AtomicString(StringImpl* baseString, unsigned start, unsigned length) : m_string(add(baseString, start, length)) { }
+ AtomicString(AtomicStringImpl*);
+ ATOMICSTRING_CONVERSION AtomicString(StringImpl*);
+ ATOMICSTRING_CONVERSION AtomicString(const String&);
+ AtomicString(StringImpl* baseString, unsigned start, unsigned length);
enum ConstructFromLiteralTag { ConstructFromLiteral };
AtomicString(const char* characters, unsigned length, ConstructFromLiteralTag)
- : m_string(addFromLiteralData(characters, length))
+ : m_string(AtomicStringImpl::addLiteral(characters, length))
{
}
template<unsigned charactersCount>
ALWAYS_INLINE AtomicString(const char (&characters)[charactersCount], ConstructFromLiteralTag)
- : m_string(addFromLiteralData(characters, charactersCount - 1))
+ : m_string(AtomicStringImpl::addLiteral(characters, charactersCount - 1))
{
COMPILE_ASSERT(charactersCount > 1, AtomicStringFromLiteralNotEmpty);
COMPILE_ASSERT((charactersCount - 1 <= ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), AtomicStringFromLiteralCannotOverflow);
AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
- static AtomicStringImpl* find(LChar* characters, unsigned length)
- {
- return findInternal(characters, length);
- }
- static AtomicStringImpl* find(UChar* characters, unsigned length)
- {
- return findInternal(characters, length);
- }
- static AtomicStringImpl* find(StringImpl* string)
- {
- if (!string || string->isAtomic())
- return static_cast<AtomicStringImpl*>(string);
- return findSlowCase(*string);
- }
-
operator const String&() const { return m_string; }
const String& string() const { return m_string; };
const LChar* characters8() const { return m_string.characters8(); }
const UChar* characters16() const { return m_string.characters16(); }
unsigned length() const { return m_string.length(); }
-
+
UChar operator[](unsigned int i) const { return m_string[i]; }
WTF_EXPORT_STRING_API static AtomicString number(int);
template<unsigned matchLength>
bool endsWith(const char (&prefix)[matchLength], bool caseSensitive = true) const
{ return m_string.endsWith<matchLength>(prefix, caseSensitive); }
-
+
WTF_EXPORT_STRING_API AtomicString convertToASCIILowercase() const;
WTF_EXPORT_STRING_API AtomicString lower() const;
AtomicString upper() const { return AtomicString(impl()->upper()); }
bool isNull() const { return m_string.isNull(); }
bool isEmpty() const { return m_string.isEmpty(); }
- static void remove(StringImpl*);
-
#if USE(CF)
- AtomicString(CFStringRef s) : m_string(add(s)) { }
-#endif
+ AtomicString(CFStringRef);
+#endif
#ifdef __OBJC__
- AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { }
+ AtomicString(NSString*);
operator NSString*() const { return m_string; }
#endif
void show() const;
#endif
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const LChar*);
- ALWAYS_INLINE static RefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const LChar*, unsigned length);
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const UChar*, unsigned length);
- ALWAYS_INLINE static RefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
- WTF_EXPORT_STRING_API static Ref<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const UChar*);
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
- ALWAYS_INLINE static RefPtr<StringImpl> add(StringImpl* string)
- {
- if (!string)
- return string;
- return add(*string);
- }
- WTF_EXPORT_STRING_API static Ref<StringImpl> addFromLiteralData(const char* characters, unsigned length);
-#if USE(CF)
- WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(CFStringRef);
-#endif
-
- template<typename StringTableProvider>
- ALWAYS_INLINE static RefPtr<StringImpl> addWithStringTableProvider(StringTableProvider& stringTableProvider, StringImpl* string)
- {
- if (!string)
- return string;
- return add(*stringTableProvider.atomicStringTable(), *string);
- }
-
-#if !ASSERT_DISABLED
- WTF_EXPORT_STRING_API static bool isInAtomicStringTable(StringImpl*);
-#endif
-
private:
// The explicit constructors with AtomicString::ConstructFromLiteral must be used for literals.
AtomicString(ASCIILiteral);
- String m_string;
-
- ALWAYS_INLINE static Ref<StringImpl> add(StringImpl& string)
- {
- if (string.isAtomic()) {
- ASSERT_WITH_MESSAGE(!string.length() || isInAtomicStringTable(&string), "The atomic string comes from an other thread!");
- return string;
- }
- return addSlowCase(string);
- }
-
- ALWAYS_INLINE static Ref<StringImpl> add(AtomicStringTable& stringTable, StringImpl& string)
- {
- if (string.isAtomic()) {
- ASSERT_WITH_MESSAGE(!string.length() || isInAtomicStringTable(&string), "The atomic string comes from an other thread!");
- return string;
- }
- return addSlowCase(stringTable, string);
- }
-
- WTF_EXPORT_STRING_API static Ref<StringImpl> addSlowCase(StringImpl&);
- WTF_EXPORT_STRING_API static Ref<StringImpl> addSlowCase(AtomicStringTable&, StringImpl&);
-
- WTF_EXPORT_STRING_API static AtomicStringImpl* findSlowCase(StringImpl&);
WTF_EXPORT_STRING_API static AtomicString fromUTF8Internal(const char*, const char*);
- WTF_EXPORT_STRING_API static AtomicStringImpl* findInternal(const LChar*, unsigned length);
- WTF_EXPORT_STRING_API static AtomicStringImpl* findInternal(const UChar*, unsigned length);
+ String m_string;
};
+static_assert(sizeof(AtomicString) == sizeof(String), "AtomicString and String must be same size!");
+
inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
bool operator==(const AtomicString&, const LChar*);
inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
template <unsigned charactersCount>
inline bool equalIgnoringASCIICase(const AtomicString& a, const char (&b)[charactersCount]) { return equalIgnoringASCIICase<charactersCount>(a.impl(), b); }
+inline AtomicString::AtomicString()
+{
+}
+
+inline AtomicString::AtomicString(const LChar* s)
+ : m_string(AtomicStringImpl::add(s))
+{
+}
+
+inline AtomicString::AtomicString(const char* s)
+ : m_string(AtomicStringImpl::add(s))
+{
+}
+
+inline AtomicString::AtomicString(const LChar* s, unsigned length)
+ : m_string(AtomicStringImpl::add(s, length))
+{
+}
+
+inline AtomicString::AtomicString(const UChar* s, unsigned length)
+ : m_string(AtomicStringImpl::add(s, length))
+{
+}
+
+inline AtomicString::AtomicString(const UChar* s, unsigned length, unsigned existingHash)
+ : m_string(AtomicStringImpl::add(s, length, existingHash))
+{
+}
+
+inline AtomicString::AtomicString(const UChar* s)
+ : m_string(AtomicStringImpl::add(s))
+{
+}
+
+inline AtomicString::AtomicString(AtomicStringImpl* imp)
+ : m_string(imp)
+{
+}
+
+inline AtomicString::AtomicString(StringImpl* imp)
+ : m_string(AtomicStringImpl::add(imp))
+{
+}
+
+inline AtomicString::AtomicString(const String& s)
+ : m_string(AtomicStringImpl::add(s.impl()))
+{
+}
+
+inline AtomicString::AtomicString(StringImpl* baseString, unsigned start, unsigned length)
+ : m_string(AtomicStringImpl::add(baseString, start, length))
+{
+}
+
+#if USE(CF)
+inline AtomicString::AtomicString(CFStringRef s)
+ : m_string(AtomicStringImpl::add(s))
+{
+}
+#endif
+
+#ifdef __OBJC__
+inline AtomicString::AtomicString(NSString* s)
+ : m_string(AtomicStringImpl::add((CFStringRef)s))
+{
+}
+#endif
+
// Define external global variables for the commonly used atomic strings.
// These are only usable from the main thread.
#ifndef ATOMICSTRING_HIDE_GLOBALS
return nullAtom;
if (!*characters)
return emptyAtom;
- return fromUTF8Internal(characters, 0);
+ return fromUTF8Internal(characters, nullptr);
}
#endif
--- /dev/null
+/*
+ * Copyright (C) 2004-2008, 2013-2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2015 Yusuke Suzuki<utatane.tea@gmail.com>. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "AtomicStringImpl.h"
+
+#include "AtomicStringTable.h"
+#include "HashSet.h"
+#include "IntegerToStringConversion.h"
+#include "StringHash.h"
+#include "Threading.h"
+#include "WTFThreadData.h"
+#include <wtf/unicode/UTF8.h>
+
+#if USE(WEB_THREAD)
+#include "SpinLock.h"
+#endif
+
+namespace WTF {
+
+using namespace Unicode;
+
+#if USE(WEB_THREAD)
+
+class AtomicStringTableLocker : public SpinLockHolder {
+ WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
+
+ static StaticSpinLock s_stringTableLock;
+public:
+ AtomicStringTableLocker()
+ : SpinLockHolder(&s_stringTableLock)
+ {
+ }
+};
+
+StaticSpinLock AtomicStringTableLocker::s_stringTableLock;
+
+#else
+
+class AtomicStringTableLocker {
+ WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
+public:
+ AtomicStringTableLocker() { }
+};
+
+#endif // USE(WEB_THREAD)
+
+static ALWAYS_INLINE HashSet<StringImpl*>& stringTable()
+{
+ return wtfThreadData().atomicStringTable()->table();
+}
+
+template<typename T, typename HashTranslator>
+static inline Ref<AtomicStringImpl> addToStringTable(const T& value)
+{
+ AtomicStringTableLocker locker;
+
+ HashSet<StringImpl*>::AddResult addResult = stringTable().add<HashTranslator>(value);
+
+ // If the string is newly-translated, then we need to adopt it.
+ // The boolean in the pair tells us if that is so.
+ if (addResult.isNewEntry)
+ return adoptRef(static_cast<AtomicStringImpl&>(**addResult.iterator));
+ return *static_cast<AtomicStringImpl*>(*addResult.iterator);
+}
+
+struct CStringTranslator {
+ static unsigned hash(const LChar* c)
+ {
+ return StringHasher::computeHashAndMaskTop8Bits(c);
+ }
+
+ static inline bool equal(StringImpl* r, const LChar* s)
+ {
+ return WTF::equal(r, s);
+ }
+
+ static void translate(StringImpl*& location, const LChar* const& c, unsigned hash)
+ {
+ location = &StringImpl::create(c).leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(const LChar* c)
+{
+ if (!c)
+ return nullptr;
+ if (!*c)
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ return addToStringTable<const LChar*, CStringTranslator>(c);
+}
+
+template<typename CharacterType>
+struct HashTranslatorCharBuffer {
+ const CharacterType* s;
+ unsigned length;
+};
+
+typedef HashTranslatorCharBuffer<UChar> UCharBuffer;
+struct UCharBufferTranslator {
+ static unsigned hash(const UCharBuffer& buf)
+ {
+ return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length);
+ }
+
+ static bool equal(StringImpl* const& str, const UCharBuffer& buf)
+ {
+ return WTF::equal(str, buf.s, buf.length);
+ }
+
+ static void translate(StringImpl*& location, const UCharBuffer& buf, unsigned hash)
+ {
+ location = &StringImpl::create8BitIfPossible(buf.s, buf.length).leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+template<typename CharacterType>
+struct HashAndCharacters {
+ unsigned hash;
+ const CharacterType* characters;
+ unsigned length;
+};
+
+template<typename CharacterType>
+struct HashAndCharactersTranslator {
+ 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<CharacterType>& buffer)
+ {
+ return WTF::equal(string, buffer.characters, buffer.length);
+ }
+
+ static void translate(StringImpl*& location, const HashAndCharacters<CharacterType>& buffer, unsigned hash)
+ {
+ location = &StringImpl::create(buffer.characters, buffer.length).leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+struct HashAndUTF8Characters {
+ unsigned hash;
+ const char* characters;
+ unsigned length;
+ unsigned utf16Length;
+};
+
+struct HashAndUTF8CharactersTranslator {
+ static unsigned hash(const HashAndUTF8Characters& buffer)
+ {
+ return buffer.hash;
+ }
+
+ static bool equal(StringImpl* const& string, const HashAndUTF8Characters& buffer)
+ {
+ if (buffer.utf16Length != string->length())
+ return false;
+
+ // If buffer contains only ASCII characters UTF-8 and UTF16 length are the same.
+ if (buffer.utf16Length != buffer.length) {
+ if (string->is8Bit())
+ return equalLatin1WithUTF8(string->characters8(), buffer.characters, buffer.characters + buffer.length);
+
+ return equalUTF16WithUTF8(string->characters16(), buffer.characters, buffer.characters + buffer.length);
+ }
+
+ if (string->is8Bit()) {
+ const LChar* stringCharacters = string->characters8();
+
+ for (unsigned i = 0; i < buffer.length; ++i) {
+ ASSERT(isASCII(buffer.characters[i]));
+ if (stringCharacters[i] != buffer.characters[i])
+ return false;
+ }
+
+ return true;
+ }
+
+ const UChar* stringCharacters = string->characters16();
+
+ for (unsigned i = 0; i < buffer.length; ++i) {
+ ASSERT(isASCII(buffer.characters[i]));
+ if (stringCharacters[i] != buffer.characters[i])
+ return false;
+ }
+
+ return true;
+ }
+
+ static void translate(StringImpl*& location, const HashAndUTF8Characters& buffer, unsigned hash)
+ {
+ UChar* target;
+ RefPtr<StringImpl> newString = StringImpl::createUninitialized(buffer.utf16Length, target);
+
+ bool isAllASCII;
+ const char* source = buffer.characters;
+ if (convertUTF8ToUTF16(&source, source + buffer.length, &target, target + buffer.utf16Length, &isAllASCII) != conversionOK)
+ ASSERT_NOT_REACHED();
+
+ if (isAllASCII)
+ newString = StringImpl::create(buffer.characters, buffer.length);
+
+ location = newString.release().leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(const UChar* s, unsigned length)
+{
+ if (!s)
+ return nullptr;
+
+ if (!length)
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ UCharBuffer buffer = { s, length };
+ return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
+}
+
+Ref<AtomicStringImpl> AtomicStringImpl::add(const UChar* s, unsigned length, unsigned existingHash)
+{
+ ASSERT(s);
+ ASSERT(existingHash);
+
+ if (!length)
+ return *static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ HashAndCharacters<UChar> buffer = { existingHash, s, length };
+ return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslator<UChar>>(buffer);
+}
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(const UChar* s)
+{
+ if (!s)
+ return nullptr;
+
+ unsigned length = 0;
+ while (s[length] != UChar(0))
+ ++length;
+
+ if (!length)
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ UCharBuffer buffer = { s, length };
+ return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
+}
+
+struct SubstringLocation {
+ StringImpl* baseString;
+ unsigned start;
+ unsigned length;
+};
+
+struct SubstringTranslator {
+ static void translate(StringImpl*& location, const SubstringLocation& buffer, unsigned hash)
+ {
+ location = &StringImpl::createSubstringSharingImpl(buffer.baseString, buffer.start, buffer.length).leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+struct SubstringTranslator8 : SubstringTranslator {
+ static unsigned hash(const SubstringLocation& buffer)
+ {
+ return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters8() + buffer.start, buffer.length);
+ }
+
+ static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
+ {
+ return WTF::equal(string, buffer.baseString->characters8() + buffer.start, buffer.length);
+ }
+};
+
+struct SubstringTranslator16 : SubstringTranslator {
+ static unsigned hash(const SubstringLocation& buffer)
+ {
+ return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters16() + buffer.start, buffer.length);
+ }
+
+ static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
+ {
+ return WTF::equal(string, buffer.baseString->characters16() + buffer.start, buffer.length);
+ }
+};
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(StringImpl* baseString, unsigned start, unsigned length)
+{
+ if (!baseString)
+ return nullptr;
+
+ if (!length || start >= baseString->length())
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ unsigned maxLength = baseString->length() - start;
+ if (length >= maxLength) {
+ if (!start)
+ return add(baseString);
+ length = maxLength;
+ }
+
+ SubstringLocation buffer = { baseString, start, length };
+ if (baseString->is8Bit())
+ return addToStringTable<SubstringLocation, SubstringTranslator8>(buffer);
+ return addToStringTable<SubstringLocation, SubstringTranslator16>(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 {
+ static unsigned hash(const CharBuffer& buf)
+ {
+ return StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const LChar*>(buf.s), buf.length);
+ }
+
+ static bool equal(StringImpl* const& str, const CharBuffer& buf)
+ {
+ return WTF::equal(str, buf.s, buf.length);
+ }
+
+ static void translate(StringImpl*& location, const CharBuffer& buf, unsigned hash)
+ {
+ location = &StringImpl::createFromLiteral(buf.s, buf.length).leakRef();
+ location->setHash(hash);
+ location->setIsAtomic(true);
+ }
+};
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(const LChar* s, unsigned length)
+{
+ if (!s)
+ return nullptr;
+
+ if (!length)
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ LCharBuffer buffer = { s, length };
+ return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer);
+}
+
+Ref<AtomicStringImpl> AtomicStringImpl::addLiteral(const char* characters, unsigned length)
+{
+ ASSERT(characters);
+ ASSERT(length);
+
+ CharBuffer buffer = { characters, length };
+ return addToStringTable<CharBuffer, CharBufferFromLiteralDataTranslator>(buffer);
+}
+
+Ref<AtomicStringImpl> AtomicStringImpl::addSlowCase(StringImpl& string)
+{
+ if (!string.length())
+ return *static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ if (string.isSymbol()) {
+ if (string.is8Bit())
+ return *add(string.characters8(), string.length());
+ return *add(string.characters16(), string.length());
+ }
+
+ ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicStringImpl should not hit the slow case if the string is already atomic.");
+
+ AtomicStringTableLocker locker;
+ auto addResult = stringTable().add(&string);
+
+ if (addResult.isNewEntry) {
+ ASSERT(*addResult.iterator == &string);
+ string.setIsAtomic(true);
+ }
+
+ return *static_cast<AtomicStringImpl*>(*addResult.iterator);
+}
+
+Ref<AtomicStringImpl> AtomicStringImpl::addSlowCase(AtomicStringTable& stringTable, StringImpl& string)
+{
+ if (!string.length())
+ return *static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ if (string.isSymbol()) {
+ if (string.is8Bit())
+ return *add(string.characters8(), string.length());
+ return *add(string.characters16(), string.length());
+ }
+
+ ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicStringImpl should not hit the slow case if the string is already atomic.");
+
+ AtomicStringTableLocker locker;
+ auto addResult = stringTable.table().add(&string);
+
+ if (addResult.isNewEntry) {
+ ASSERT(*addResult.iterator == &string);
+ string.setIsAtomic(true);
+ }
+
+ return *static_cast<AtomicStringImpl*>(*addResult.iterator);
+}
+
+void AtomicStringImpl::remove(AtomicStringImpl* string)
+{
+ ASSERT(string->isAtomic());
+ AtomicStringTableLocker locker;
+ HashSet<StringImpl*>& atomicStringTable = stringTable();
+ HashSet<StringImpl*>::iterator iterator = atomicStringTable.find(string);
+ ASSERT_WITH_MESSAGE(iterator != atomicStringTable.end(), "The string being removed is atomic in the string table of an other thread!");
+ atomicStringTable.remove(iterator);
+}
+
+AtomicStringImpl* AtomicStringImpl::lookUpSlowCase(StringImpl& string)
+{
+ ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicStringImpls should return from the fast case.");
+
+ if (!string.length())
+ return static_cast<AtomicStringImpl*>(StringImpl::empty());
+
+ if (string.isSymbol()) {
+ if (string.is8Bit())
+ return lookUpInternal(string.characters8(), string.length());
+ return lookUpInternal(string.characters16(), string.length());
+ }
+
+ AtomicStringTableLocker locker;
+ HashSet<StringImpl*>& atomicStringTable = stringTable();
+ auto iterator = atomicStringTable.find(&string);
+ if (iterator != atomicStringTable.end())
+ return static_cast<AtomicStringImpl*>(*iterator);
+ return nullptr;
+}
+
+RefPtr<AtomicStringImpl> AtomicStringImpl::addUTF8(const char* charactersStart, const char* charactersEnd)
+{
+ HashAndUTF8Characters buffer;
+ buffer.characters = charactersStart;
+ buffer.hash = calculateStringHashAndLengthFromUTF8MaskingTop8Bits(charactersStart, charactersEnd, buffer.length, buffer.utf16Length);
+
+ if (!buffer.hash)
+ return nullptr;
+
+ return addToStringTable<HashAndUTF8Characters, HashAndUTF8CharactersTranslator>(buffer);
+}
+
+AtomicStringImpl* AtomicStringImpl::lookUpInternal(const LChar* characters, unsigned length)
+{
+ AtomicStringTableLocker locker;
+ auto& table = stringTable();
+
+ LCharBuffer buffer = { characters, length };
+ auto iterator = table.find<LCharBufferTranslator>(buffer);
+ if (iterator != table.end())
+ return static_cast<AtomicStringImpl*>(*iterator);
+ return nullptr;
+}
+
+AtomicStringImpl* AtomicStringImpl::lookUpInternal(const UChar* characters, unsigned length)
+{
+ AtomicStringTableLocker locker;
+ auto& table = stringTable();
+
+ UCharBuffer buffer = { characters, length };
+ auto iterator = table.find<UCharBufferTranslator>(buffer);
+ if (iterator != table.end())
+ return static_cast<AtomicStringImpl*>(*iterator);
+ return nullptr;
+}
+
+#if !ASSERT_DISABLED
+bool AtomicStringImpl::isInAtomicStringTable(StringImpl* string)
+{
+ AtomicStringTableLocker locker;
+ return stringTable().contains(string);
+}
+#endif
+
+} // namespace WTF
namespace WTF {
-class AtomicStringImpl : public StringImpl
-{
+class AtomicStringTable;
+
+class AtomicStringImpl : public StringImpl {
public:
- AtomicStringImpl() : StringImpl(0) {}
+ static AtomicStringImpl* lookUp(LChar* characters, unsigned length)
+ {
+ return lookUpInternal(characters, length);
+ }
+ static AtomicStringImpl* lookUp(UChar* characters, unsigned length)
+ {
+ return lookUpInternal(characters, length);
+ }
+ static AtomicStringImpl* lookUp(StringImpl* string)
+ {
+ if (!string || string->isAtomic())
+ return static_cast<AtomicStringImpl*>(string);
+ return lookUpSlowCase(*string);
+ }
+
+ static void remove(AtomicStringImpl*);
+
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(const LChar*);
+ ALWAYS_INLINE static RefPtr<AtomicStringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(const LChar*, unsigned length);
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(const UChar*, unsigned length);
+ ALWAYS_INLINE static RefPtr<AtomicStringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
+ WTF_EXPORT_STRING_API static Ref<AtomicStringImpl> add(const UChar*, unsigned length, unsigned existingHash);
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(const UChar*);
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(StringImpl*, unsigned offset, unsigned length);
+ ALWAYS_INLINE static RefPtr<AtomicStringImpl> add(StringImpl* string)
+ {
+ if (!string)
+ return static_cast<AtomicStringImpl*>(string);
+ return add(*string);
+ }
+ WTF_EXPORT_STRING_API static Ref<AtomicStringImpl> addLiteral(const char* characters, unsigned length);
+
+ // Returns null if the input data contains an invalid UTF-8 sequence.
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> addUTF8(const char* start, const char* end);
+#if USE(CF)
+ WTF_EXPORT_STRING_API static RefPtr<AtomicStringImpl> add(CFStringRef);
+#endif
+
+ template<typename StringTableProvider>
+ ALWAYS_INLINE static RefPtr<AtomicStringImpl> addWithStringTableProvider(StringTableProvider& stringTableProvider, StringImpl* string)
+ {
+ if (!string)
+ return nullptr;
+ return add(*stringTableProvider.atomicStringTable(), *string);
+ }
+
+#if !ASSERT_DISABLED
+ WTF_EXPORT_STRING_API static bool isInAtomicStringTable(StringImpl*);
+#endif
+
+private:
+ AtomicStringImpl() = delete;
+
+ ALWAYS_INLINE static Ref<AtomicStringImpl> add(StringImpl& string)
+ {
+ if (string.isAtomic()) {
+ ASSERT_WITH_MESSAGE(!string.length() || isInAtomicStringTable(&string), "The atomic string comes from an other thread!");
+ return static_cast<AtomicStringImpl&>(string);
+ }
+ return addSlowCase(string);
+ }
+
+ ALWAYS_INLINE static Ref<AtomicStringImpl> add(AtomicStringTable& stringTable, StringImpl& string)
+ {
+ if (string.isAtomic()) {
+ ASSERT_WITH_MESSAGE(!string.length() || isInAtomicStringTable(&string), "The atomic string comes from an other thread!");
+ return static_cast<AtomicStringImpl&>(string);
+ }
+ return addSlowCase(stringTable, string);
+ }
+
+ WTF_EXPORT_STRING_API static Ref<AtomicStringImpl> addSlowCase(StringImpl&);
+ WTF_EXPORT_STRING_API static Ref<AtomicStringImpl> addSlowCase(AtomicStringTable&, StringImpl&);
+
+ WTF_EXPORT_STRING_API static AtomicStringImpl* lookUpSlowCase(StringImpl&);
+
+ WTF_EXPORT_STRING_API static AtomicStringImpl* lookUpInternal(const LChar*, unsigned length);
+ WTF_EXPORT_STRING_API static AtomicStringImpl* lookUpInternal(const UChar*, unsigned length);
};
#if !ASSERT_DISABLED
STRING_STATS_REMOVE_STRING(*this);
if (isAtomic() && length() && !isSymbol())
- AtomicString::remove(this);
+ AtomicStringImpl::remove(static_cast<AtomicStringImpl*>(this));
if (isSymbol() && symbolRegistry())
symbolRegistry()->remove(this);
friend struct WTF::LCharBufferTranslator;
friend struct WTF::SubstringTranslator;
friend struct WTF::UCharBufferTranslator;
- friend class AtomicStringImpl;
friend class JSC::LLInt::Data;
friend class JSC::LLIntOffsetsExtractor;
STRING_STATS_ADD_16BIT_STRING2(m_length, true);
}
- ~StringImpl();
-
public:
WTF_EXPORT_STRING_API static void destroy(StringImpl*);
return *reinterpret_cast<unsigned*>((tailPointer<SymbolRegistry*>() + 2));
}
+protected:
+ ~StringImpl();
+
private:
bool requiresCopy() const
{
WTF_EXPORT_STRING_API String(const char* characters);
// Construct a string referencing an existing StringImpl.
- String(StringImpl& impl) : m_impl(&impl) { }
- String(StringImpl* impl) : m_impl(impl) { }
- String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
- String(Ref<StringImpl>&& impl) : m_impl(WTF::move(impl)) { }
- String(RefPtr<StringImpl>&& impl) : m_impl(impl) { }
+ String(StringImpl&);
+ String(StringImpl*);
+ String(PassRefPtr<StringImpl>);
+ String(Ref<StringImpl>&&);
+ String(RefPtr<StringImpl>&&);
+
+ String(Ref<AtomicStringImpl>&&);
+ String(RefPtr<AtomicStringImpl>&&);
// Construct a string from a constant string literal.
WTF_EXPORT_STRING_API String(ASCIILiteral characters);
// Definitions of string operations
+inline String::String(StringImpl& impl)
+ : m_impl(&impl)
+{
+}
+
+inline String::String(StringImpl* impl)
+ : m_impl(impl)
+{
+}
+
+inline String::String(PassRefPtr<StringImpl> impl)
+ : m_impl(impl)
+{
+}
+
+inline String::String(Ref<StringImpl>&& impl)
+ : m_impl(WTF::move(impl))
+{
+}
+
+inline String::String(RefPtr<StringImpl>&& impl)
+ : m_impl(WTF::move(impl))
+{
+}
+
+inline String::String(Ref<AtomicStringImpl>&& impl)
+ : m_impl(WTF::move(impl))
+{
+}
+
+inline String::String(RefPtr<AtomicStringImpl>&& impl)
+ : m_impl(WTF::move(impl))
+{
+}
+
template<size_t inlineCapacity, typename OverflowHandler>
String::String(const Vector<UChar, inlineCapacity, OverflowHandler>& vector)
: m_impl(vector.size() ? StringImpl::create(vector.data(), vector.size()) : Ref<StringImpl>(*StringImpl::empty()))
*/
#include "config.h"
-#include <wtf/text/AtomicString.h>
+#include <wtf/text/AtomicStringImpl.h>
#if USE(CF)
namespace WTF {
-RefPtr<StringImpl> AtomicString::add(CFStringRef string)
+RefPtr<AtomicStringImpl> AtomicStringImpl::add(CFStringRef string)
{
if (!string)
return nullptr;
+2015-05-19 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ Move AtomicStringImpl table related operations from AtomicString to AtomicStringImpl
+ https://bugs.webkit.org/show_bug.cgi?id=145109
+
+ Reviewed by Darin Adler.
+
+ * dom/TreeScope.cpp:
+ (WebCore::TreeScope::getElementById):
+
2015-05-19 Jon Lee <jonlee@apple.com>
[iOS] Optimized fullscreen placeholder is incorrectly sized
if (!m_elementsById)
return nullptr;
- if (AtomicStringImpl* atomicElementId = AtomicString::find(elementId.impl()))
+ if (AtomicStringImpl* atomicElementId = AtomicStringImpl::lookUp(elementId.impl()))
return m_elementsById->getElementById(*atomicElementId, *this);
return nullptr;
+2015-05-19 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ Move AtomicStringImpl table related operations from AtomicString to AtomicStringImpl
+ https://bugs.webkit.org/show_bug.cgi?id=145109
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
+ (TestWebKitAPI::TEST):
+
2015-05-19 Anders Carlsson <andersca@apple.com>
Add alternate menu items for performing operations on the default data store
ASSERT_TRUE(reference->isSymbol());
ASSERT_FALSE(reference->isAtomic());
- RefPtr<StringImpl> atomic = AtomicString::add(reference.get());
+ RefPtr<StringImpl> atomic = AtomicStringImpl::add(reference.get());
ASSERT_TRUE(atomic->isAtomic());
ASSERT_FALSE(atomic->isSymbol());
ASSERT_TRUE(reference->isSymbol());
ASSERT_TRUE(reference->isSymbol());
ASSERT_FALSE(reference->isAtomic());
- RefPtr<StringImpl> atomic = AtomicString::add(reference.get());
+ RefPtr<StringImpl> atomic = AtomicStringImpl::add(reference.get());
ASSERT_TRUE(atomic->isAtomic());
ASSERT_FALSE(atomic->isSymbol());
ASSERT_TRUE(reference->isSymbol());