示例#1
0
ALWAYS_INLINE void MarkStack::internalAppend(JSValue* slot)
{
    // This internalAppend is only intended for visits to object and array backing stores.
    // as it can change the JSValue pointed to be the argument when the original JSValue
    // is a string that contains the same contents as another string.

    ASSERT(slot);
    JSValue value = *slot;
    ASSERT(value);
    if (!value.isCell())
        return;

    JSCell* cell = value.asCell();
    if (!cell)
        return;

    if (m_shouldHashConst && cell->isString()) {
        JSString* string = jsCast<JSString*>(cell);
        if (string->shouldTryHashConst() && string->tryHashConstLock()) {
            UniqueStringMap::AddResult addResult = m_uniqueStrings.add(string->string().impl(), value);
            if (addResult.isNewEntry)
                string->setHashConstSingleton();
            else {
                JSValue existingJSValue = addResult.iterator->second;
                if (value != existingJSValue)
                    jsCast<JSString*>(existingJSValue.asCell())->clearHashConstSingleton();
                *slot = existingJSValue;
                string->releaseHashConstLock();
                return;
            }
            string->releaseHashConstLock();
        }
    }

    internalAppend(cell);
}