+2014-02-10 Andreas Kling <akling@apple.com>
+
+ Make the Identifier::add() family return PassRef<StringImpl>.
+ <https://webkit.org/b/128542>
+
+ This knocks one branch off of creating an Identifier from another
+ string source.
+
+ Reviewed by Oliver Hunt.
+
+ * runtime/Identifier.cpp:
+ (JSC::Identifier::add):
+ (JSC::Identifier::add8):
+ (JSC::Identifier::addSlowCase):
+ * runtime/Identifier.h:
+ (JSC::Identifier::add):
+ * runtime/Lookup.cpp:
+ (JSC::HashTable::createTable):
+
2014-02-09 Mark Lam <mark.lam@apple.com>
Remove unnecessary spinLock in JSLock.
}
};
-PassRefPtr<StringImpl> Identifier::add(VM* vm, const char* c)
+PassRef<StringImpl> Identifier::add(VM* vm, const char* c)
{
ASSERT(c);
ASSERT(c[0]);
// The boolean in the pair tells us if that is so.
RefPtr<StringImpl> addedString = addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
- return addedString.release();
+ return addedString.releaseNonNull();
}
-PassRefPtr<StringImpl> Identifier::add(ExecState* exec, const char* c)
+PassRef<StringImpl> Identifier::add(ExecState* exec, const char* c)
{
return add(&exec->vm(), c);
}
-PassRefPtr<StringImpl> Identifier::add8(VM* vm, const UChar* s, int length)
+PassRef<StringImpl> Identifier::add8(VM* vm, const UChar* s, int length)
{
if (length == 1) {
UChar c = s[0];
}
if (!length)
- return StringImpl::empty();
+ return *StringImpl::empty();
CharBuffer<UChar> buf = { s, static_cast<unsigned>(length) };
HashSet<StringImpl*>::AddResult addResult = vm->identifierTable->add<CharBuffer<UChar>, IdentifierLCharFromUCharTranslator >(buf);
// If the string is newly-translated, then we need to adopt it.
// The boolean in the pair tells us if that is so.
- return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
+ return addResult.isNewEntry ? adoptRef(**addResult.iterator) : **addResult.iterator;
}
-PassRefPtr<StringImpl> Identifier::addSlowCase(VM* vm, StringImpl* r)
+PassRef<StringImpl> Identifier::addSlowCase(VM* vm, StringImpl* r)
{
if (r->isEmptyUnique())
- return r;
+ return *r;
ASSERT(!r->isIdentifier());
// The empty & null strings are static singletons, and static strings are handled
// in ::add() in the header, so we should never get here with a zero length string.
if (c <= maxSingleCharacterString)
r = vm->smallStrings.singleCharacterStringRep(c);
if (r->isIdentifier())
- return r;
+ return *r;
}
- return *vm->identifierTable->add(r).iterator;
+ return **vm->identifierTable->add(r).iterator;
}
-PassRefPtr<StringImpl> Identifier::addSlowCase(ExecState* exec, StringImpl* r)
+PassRef<StringImpl> Identifier::addSlowCase(ExecState* exec, StringImpl* r)
{
return addSlowCase(&exec->vm(), r);
}
static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); }
// Only to be used with string literals.
- static PassRefPtr<StringImpl> add(VM*, const char*);
- JS_EXPORT_PRIVATE static PassRefPtr<StringImpl> add(ExecState*, const char*);
+ static PassRef<StringImpl> add(VM*, const char*);
+ JS_EXPORT_PRIVATE static PassRef<StringImpl> add(ExecState*, const char*);
private:
String m_string;
static bool equal(const Identifier& a, const Identifier& b) { return a.m_string.impl() == b.m_string.impl(); }
static bool equal(const Identifier& a, const LChar* b) { return equal(a.m_string.impl(), b); }
- template <typename T> static PassRefPtr<StringImpl> add(VM*, const T*, int length);
- static PassRefPtr<StringImpl> add8(VM*, const UChar*, int length);
+ template <typename T> static PassRef<StringImpl> add(VM*, const T*, int length);
+ static PassRef<StringImpl> add8(VM*, const UChar*, int length);
template <typename T> ALWAYS_INLINE static bool canUseSingleCharacterString(T);
- static PassRefPtr<StringImpl> add(ExecState* exec, StringImpl* r)
+ static PassRef<StringImpl> add(ExecState* exec, StringImpl* r)
{
#ifndef NDEBUG
checkCurrentIdentifierTable(exec);
#endif
if (r->isIdentifier())
- return r;
+ return *r;
return addSlowCase(exec, r);
}
- static PassRefPtr<StringImpl> add(VM* vm, StringImpl* r)
+ static PassRef<StringImpl> add(VM* vm, StringImpl* r)
{
#ifndef NDEBUG
checkCurrentIdentifierTable(vm);
#endif
if (r->isIdentifier())
- return r;
+ return *r;
return addSlowCase(vm, r);
}
- JS_EXPORT_PRIVATE static PassRefPtr<StringImpl> addSlowCase(ExecState*, StringImpl* r);
- JS_EXPORT_PRIVATE static PassRefPtr<StringImpl> addSlowCase(VM*, StringImpl* r);
+ JS_EXPORT_PRIVATE static PassRef<StringImpl> addSlowCase(ExecState*, StringImpl* r);
+ JS_EXPORT_PRIVATE static PassRef<StringImpl> addSlowCase(VM*, StringImpl* r);
JS_EXPORT_PRIVATE static void checkCurrentIdentifierTable(ExecState*);
JS_EXPORT_PRIVATE static void checkCurrentIdentifierTable(VM*);
};
template <typename T>
- PassRefPtr<StringImpl> Identifier::add(VM* vm, const T* s, int length)
+ PassRef<StringImpl> Identifier::add(VM* vm, const T* s, int length)
{
if (length == 1) {
T c = s[0];
}
if (!length)
- return StringImpl::empty();
+ return *StringImpl::empty();
CharBuffer<T> buf = { s, static_cast<unsigned>(length) };
HashSet<StringImpl*>::AddResult addResult = vm->identifierTable->add<CharBuffer<T>, IdentifierCharBufferTranslator<T>>(buf);
// If the string is newly-translated, then we need to adopt it.
// The boolean in the pair tells us if that is so.
- return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
+ return addResult.isNewEntry ? adoptRef(**addResult.iterator) : **addResult.iterator;
}
inline bool operator==(const Identifier& a, const Identifier& b)
for (int i = 0; i < compactSize; ++i)
entries[i].setKey(0);
for (int i = 0; values[i].key; ++i) {
- StringImpl* identifier = Identifier::add(&vm, values[i].key).leakRef();
- int hashIndex = identifier->existingHash() & compactHashSizeMask;
+ StringImpl& identifier = Identifier::add(&vm, values[i].key).leakRef();
+ int hashIndex = identifier.existingHash() & compactHashSizeMask;
HashEntry* entry = &entries[hashIndex];
if (entry->key()) {
entry = entry->next();
}
- entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2, values[i].intrinsic);
+ entry->initialize(&identifier, values[i].attributes, values[i].value1, values[i].value2, values[i].intrinsic);
}
table = entries;
}