Ignore:
Timestamp:
May 19, 2015, 10:06:23 AM (10 years ago)
Author:
[email protected]
Message:

Give JSString a StringView getter and start using it.
<https://webkit.org/b/145131>

Reviewed by Anders Carlsson.

When JSString is a substring internally, calling value(ExecState*) on it
will reify the baseString/start/length tuple into a new StringImpl.

For clients that only want to look at the characters of a JSString, but
don't actually need a reffable StringImpl, adding a light-weight StringView
getter lets them avoid constructing anything.

This patch adds JSString::view(ExecState*) and uses it in a few places.
There are many more opportunities to use this API, but let's do a few things
at a time.

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunctionSkippingEvalEnabledCheck):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::decode):
(JSC::parseInt):
(JSC::jsToNumber):
(JSC::parseFloat):
(JSC::globalFuncParseInt):
(JSC::globalFuncParseFloat):
(JSC::globalFuncEscape):
(JSC::globalFuncUnescape):

  • runtime/JSGlobalObjectFunctions.h:
  • runtime/JSONObject.cpp:

(JSC::JSONProtoFuncParse):

  • runtime/JSString.cpp:

(JSC::JSString::getPrimitiveNumber):
(JSC::JSString::toNumber):

  • runtime/JSString.h:

(JSC::JSRopeString::view):
(JSC::JSString::view):

File:
1 edited

Legend:

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

    r182747 r184575  
    3131#include "Structure.h"
    3232#include <array>
     33#include <wtf/text/StringView.h>
    3334
    3435namespace JSC {
     
    144145    AtomicString toAtomicString(ExecState*) const;
    145146    AtomicStringImpl* toExistingAtomicString(ExecState*) const;
     147    StringView view(ExecState*) const;
    146148    const String& value(ExecState*) const;
    147149    const String& tryGetValue() const;
     
    370372    void resolveRopeInternal16NoSubstring(UChar*) const;
    371373    void clearFibers() const;
     374    StringView view(ExecState*) const;
    372375
    373376    JS_EXPORT_PRIVATE JSString* getIndexSlowCase(ExecState*, unsigned);
     
    699702}
    700703
     704ALWAYS_INLINE StringView JSRopeString::view(ExecState* exec) const
     705{
     706    if (isSubstring()) {
     707        if (is8Bit())
     708            return StringView(substringBase()->m_value.characters8() + substringOffset(), m_length);
     709        return StringView(substringBase()->m_value.characters16() + substringOffset(), m_length);
     710    }
     711    resolveRope(exec);
     712    return StringView(m_value);
     713}
     714
     715ALWAYS_INLINE StringView JSString::view(ExecState* exec) const
     716{
     717    if (isRope())
     718        return static_cast<const JSRopeString*>(this)->view(exec);
     719    return StringView(m_value);
     720}
     721
    701722} // namespace JSC
    702723
Note: See TracChangeset for help on using the changeset viewer.