Skip to content

Commit

Permalink
[WTF] Added support for private registered symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
MCE-KobyBo committed Feb 4, 2018
1 parent 9a812c9 commit d1c5146
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Source/WTF/wtf/text/SymbolImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ Ref<PrivateSymbolImpl> PrivateSymbolImpl::createNullSymbol()
return adoptRef(*new PrivateSymbolImpl);
}

Ref<RegisteredSymbolImpl> RegisteredSymbolImpl::create(StringImpl& rep, SymbolRegistry& symbolRegistry)
Ref<RegisteredSymbolImpl> RegisteredSymbolImpl::create(StringImpl& rep, SymbolRegistry& symbolRegistry, bool isPrivate)
{
auto* ownerRep = (rep.bufferOwnership() == BufferSubstring) ? rep.substringBuffer() : &rep;
ASSERT(ownerRep->bufferOwnership() != BufferSubstring);
if (rep.is8Bit())
return adoptRef(*new RegisteredSymbolImpl(rep.m_data8, rep.length(), *ownerRep, symbolRegistry));
return adoptRef(*new RegisteredSymbolImpl(rep.m_data16, rep.length(), *ownerRep, symbolRegistry));
return adoptRef(*new RegisteredSymbolImpl(rep.m_data8, rep.length(), *ownerRep, symbolRegistry, isPrivate));
return adoptRef(*new RegisteredSymbolImpl(rep.m_data16, rep.length(), *ownerRep, symbolRegistry, isPrivate));
}

} // namespace WTF
10 changes: 5 additions & 5 deletions Source/WTF/wtf/text/SymbolImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ class RegisteredSymbolImpl : public SymbolImpl {
SymbolRegistry* symbolRegistry() const { return m_symbolRegistry; }
void clearSymbolRegistry() { m_symbolRegistry = nullptr; }

static Ref<RegisteredSymbolImpl> create(StringImpl& rep, SymbolRegistry&);
static Ref<RegisteredSymbolImpl> create(StringImpl& rep, SymbolRegistry&, bool isPrivate);

RegisteredSymbolImpl(const LChar* characters, unsigned length, Ref<StringImpl>&& base, SymbolRegistry& registry)
: SymbolImpl(characters, length, WTFMove(base), s_flagIsRegistered)
RegisteredSymbolImpl(const LChar* characters, unsigned length, Ref<StringImpl>&& base, SymbolRegistry& registry, bool isPrivate)
: SymbolImpl(characters, length, WTFMove(base), s_flagIsRegistered | (isPrivate ? s_flagIsPrivate : 0))
, m_symbolRegistry(&registry)
{
}

RegisteredSymbolImpl(const UChar* characters, unsigned length, Ref<StringImpl>&& base, SymbolRegistry& registry)
: SymbolImpl(characters, length, WTFMove(base), s_flagIsRegistered)
RegisteredSymbolImpl(const UChar* characters, unsigned length, Ref<StringImpl>&& base, SymbolRegistry& registry, bool isPrivate)
: SymbolImpl(characters, length, WTFMove(base), s_flagIsRegistered | (isPrivate ? s_flagIsPrivate : 0))
, m_symbolRegistry(&registry)
{
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/SymbolRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Ref<RegisteredSymbolImpl> SymbolRegistry::symbolForKey(const String& rep)
return *static_cast<SymbolImpl*>(addResult.iterator->impl())->asRegisteredSymbolImpl();
}

auto symbol = RegisteredSymbolImpl::create(*rep.impl(), *this);
auto symbol = RegisteredSymbolImpl::create(*rep.impl(), *this, m_createPrivateSymbols);
*addResult.iterator = SymbolRegistryKey(&symbol.get());
return symbol;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/WTF/wtf/text/SymbolRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ template<> struct HashTraits<SymbolRegistryKey> : SimpleClassHashTraits<SymbolRe
class SymbolRegistry {
WTF_MAKE_NONCOPYABLE(SymbolRegistry);
public:
SymbolRegistry() = default;
SymbolRegistry(bool createPrivateSymbols = false) : m_createPrivateSymbols(createPrivateSymbols) {};
WTF_EXPORT_PRIVATE ~SymbolRegistry();

WTF_EXPORT_PRIVATE Ref<RegisteredSymbolImpl> symbolForKey(const String&);
Expand All @@ -88,6 +88,7 @@ class SymbolRegistry {

private:
HashSet<SymbolRegistryKey> m_table;
bool m_createPrivateSymbols;
};

inline SymbolRegistryKey::SymbolRegistryKey(StringImpl* uid)
Expand Down

0 comments on commit d1c5146

Please sign in to comment.