void JSRopeString::resolveRopeToAtomicString(ExecState* exec) const { if (length() > maxLengthForOnStackResolve) { resolveRope(exec); m_value = AtomicString(m_value); setIs8Bit(m_value.impl()->is8Bit()); return; } if (is8Bit()) { LChar buffer[maxLengthForOnStackResolve]; resolveRopeInternal8(buffer); m_value = AtomicString(buffer, length()); setIs8Bit(m_value.impl()->is8Bit()); } else { UChar buffer[maxLengthForOnStackResolve]; resolveRopeInternal16(buffer); m_value = AtomicString(buffer, length()); setIs8Bit(m_value.impl()->is8Bit()); } clearFibers(); // If we resolved a string that didn't previously exist, notify the heap that we've grown. if (m_value.impl()->hasOneRef()) Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost()); }
RefPtr<AtomicStringImpl> JSRopeString::resolveRopeToExistingAtomicString(ExecState* exec) const { if (length() > maxLengthForOnStackResolve) { resolveRope(exec); if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(m_value.impl())) { m_value = *existingAtomicString; setIs8Bit(m_value.impl()->is8Bit()); clearFibers(); return existingAtomicString; } return nullptr; } if (is8Bit()) { LChar buffer[maxLengthForOnStackResolve]; resolveRopeInternal8(buffer); if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(buffer, length())) { m_value = *existingAtomicString; setIs8Bit(m_value.impl()->is8Bit()); clearFibers(); return existingAtomicString; } } else { UChar buffer[maxLengthForOnStackResolve]; resolveRopeInternal16(buffer); if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(buffer, length())) { m_value = *existingAtomicString; setIs8Bit(m_value.impl()->is8Bit()); clearFibers(); return existingAtomicString; } } return nullptr; }
void JSRopeString::resolveRope(ExecState* exec) const { ASSERT(isRope()); if (is8Bit()) { LChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } resolveRopeInternal8(buffer); clearFibers(); ASSERT(!isRope()); return; } UChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } resolveRopeInternal16(buffer); clearFibers(); ASSERT(!isRope()); }