Ignore:
Timestamp:
May 26, 2015, 11:54:01 AM (10 years ago)
Author:
[email protected]
Message:

String.prototype.charAt() should use StringView.
<https://webkit.org/b/145352>

Reviewed by Darin Adler.

Remove the jsSingleCharacterSubstring() function since it's actually completely
counter-productive: it could create a single-character string that would retain
a much larger string for the duration of its lifetime.

This made sense before StringImpl learned to put its characters at the tail end
of its own allocation. Now that it does, it's far better to just create a new
single-character StringImpl.

With that out of the way, we can make String.prototype.charAt() use StringView
to avoid reifying substring JSStrings (and avoid some ref churn too.)

  • runtime/JSString.cpp:

(JSC::JSRopeString::getIndexSlowCase):

  • runtime/JSString.h:

(JSC::JSString::getIndex):
(JSC::jsSingleCharacterSubstring): Deleted.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncCharAt):
(JSC::stringProtoFuncSplit):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r184612 r184865  
    4646JSString* jsSingleCharacterString(VM*, UChar);
    4747JSString* jsSingleCharacterString(ExecState*, UChar);
    48 JSString* jsSingleCharacterSubstring(ExecState*, const String&, unsigned offset);
    4948JSString* jsSubstring(VM*, const String&, unsigned offset, unsigned length);
    5049JSString* jsSubstring(ExecState*, const String&, unsigned offset, unsigned length);
     
    445444}
    446445
    447 ALWAYS_INLINE JSString* jsSingleCharacterSubstring(ExecState* exec, const String& s, unsigned offset)
    448 {
    449     VM* vm = &exec->vm();
    450     ASSERT(offset < static_cast<unsigned>(s.length()));
    451     UChar c = s.characterAt(offset);
    452     if (c <= maxSingleCharacterString)
    453         return vm->smallStrings.singleCharacterString(c);
    454     return JSString::create(*vm, StringImpl::createSubstringSharingImpl(s.impl(), offset, 1));
    455 }
    456 
    457446inline JSString* jsNontrivialString(VM* vm, const String& s)
    458447{
     
    508497        return static_cast<JSRopeString*>(this)->getIndexSlowCase(exec, i);
    509498    ASSERT(i < m_value.length());
    510     return jsSingleCharacterSubstring(exec, m_value, i);
     499    return jsSingleCharacterString(exec, m_value[i]);
    511500}
    512501
Note: See TracChangeset for help on using the changeset viewer.