void JSString::resolveRope(ExecState* exec) const { ASSERT(isRope()); UChar* buffer; if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) m_value = newImpl; else { outOfMemory(exec); return; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase(exec, buffer); } UChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); ASSERT(!isRope()); }
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; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase8(buffer); } LChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters8(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); 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; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase(buffer); } UChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); ASSERT(!isRope()); }
void TiString::resolveRope(TiExcState* exec) const { ASSERT(isRope()); UChar* buffer; if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) m_value = newImpl; else { outOfMemory(exec); return; } RopeImpl::Fiber currentFiber = m_fibers[0]; if ((m_fiberCount > 2) || (RopeImpl::isRope(currentFiber)) || ((m_fiberCount == 2) && (RopeImpl::isRope(m_fibers[1])))) { resolveRopeSlowCase(exec, buffer); return; } UChar* position = buffer; StringImpl* string = static_cast<StringImpl*>(currentFiber); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); if (m_fiberCount > 1) { position += length; currentFiber = m_fibers[1]; string = static_cast<StringImpl*>(currentFiber); length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; } ASSERT((buffer + m_length) == position); for (unsigned i = 0; i < m_fiberCount; ++i) { RopeImpl::deref(m_fibers[i]); m_fibers[i] = 0; } m_fiberCount = 0; ASSERT(!isRope()); }
void JSRopeString::resolveRopeInternal16NoSubstring(UChar* buffer) const { for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) { if (fiber(i)->isRope()) { resolveRopeSlowCase(buffer); return; } } UChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) { const StringImpl& fiberString = *fiber(i)->m_value.impl(); unsigned length = fiberString.length(); if (fiberString.is8Bit()) StringImpl::copyChars(position, fiberString.characters8(), length); else StringImpl::copyChars(position, fiberString.characters16(), length); position += length; } ASSERT((buffer + length()) == position); }