Changeset 252464 in webkit


Ignore:
Timestamp:
Nov 14, 2019 1:59:58 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

Use toLength() and getIndexQuickly() in JSON.stringify
https://bugs.webkit.org/show_bug.cgi?id=204122

Patch by Alexey Shvayka <Alexey Shvayka> on 2019-11-14
Reviewed by Yusuke Suzuki.

JSTests:

  • microbenchmarks/json-stringify-array-replacer.js: Added.
  • microbenchmarks/json-stringify-empty-array.js: Added.

Source/JavaScriptCore:

Using toLength() is semantically equivalent and performance-neutral, while adding
JSObject::getIndexQuickly() advances microbenchmarks/json-stringify-array-replacer.js
by 34%.

  • runtime/JSONObject.cpp:

(JSC::Stringifier::Stringifier):
(JSC::Stringifier::Holder::appendNextProperty):

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r252463 r252464  
     12019-11-14  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Use toLength() and getIndexQuickly() in JSON.stringify
     4        https://bugs.webkit.org/show_bug.cgi?id=204122
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * microbenchmarks/json-stringify-array-replacer.js: Added.
     9        * microbenchmarks/json-stringify-empty-array.js: Added.
     10
    1112019-11-14  Caio Lima  <ticaiolima@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r252463 r252464  
     12019-11-14  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Use toLength() and getIndexQuickly() in JSON.stringify
     4        https://bugs.webkit.org/show_bug.cgi?id=204122
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Using toLength() is semantically equivalent and performance-neutral, while adding
     9        JSObject::getIndexQuickly() advances microbenchmarks/json-stringify-array-replacer.js
     10        by 34%.
     11
     12        * runtime/JSONObject.cpp:
     13        (JSC::Stringifier::Stringifier):
     14        (JSC::Stringifier::Holder::appendNextProperty):
     15
    1162019-11-14  Caio Lima  <ticaiolima@gmail.com>
    217
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r251425 r252464  
    238238            if (isArrayReplacer) {
    239239                m_usingArrayReplacer = true;
    240                 JSValue lengthValue = replacerObject->get(globalObject, vm.propertyNames->length);
     240                unsigned length = toLength(globalObject, replacerObject);
    241241                RETURN_IF_EXCEPTION(scope, );
    242                 unsigned length = lengthValue.toUInt32(globalObject);
    243                 RETURN_IF_EXCEPTION(scope, );
    244                 for (unsigned i = 0; i < length; ++i) {
    245                     JSValue name = replacerObject->get(globalObject, i);
    246                     RETURN_IF_EXCEPTION(scope, );
     242                for (unsigned index = 0; index < length; ++index) {
     243                    JSValue name;
     244                    if (isJSArray(replacerObject) && replacerObject->canGetIndexQuickly(index))
     245                        name = replacerObject->getIndexQuickly(index);
     246                    else {
     247                        name = replacerObject->get(globalObject, index);
     248                        RETURN_IF_EXCEPTION(scope, );
     249                    }
    247250                    if (name.isObject()) {
    248251                        auto* nameObject = jsCast<JSObject*>(name);
     
    487490    if (!m_index) {
    488491        if (m_isArray) {
    489             if (m_isJSArray)
    490                 m_size = asArray(m_object)->length();
    491             else {
    492                 JSValue value = m_object->get(globalObject, vm.propertyNames->length);
    493                 RETURN_IF_EXCEPTION(scope, false);
    494                 m_size = value.toUInt32(globalObject);
    495                 RETURN_IF_EXCEPTION(scope, false);
    496             }
     492            m_size = toLength(globalObject, m_object);
     493            RETURN_IF_EXCEPTION(scope, false);
    497494            builder.append('[');
    498495        } else {
     
    529526        // Get the value.
    530527        JSValue value;
    531         if (m_isJSArray && asArray(m_object)->canGetIndexQuickly(index))
    532             value = asArray(m_object)->getIndexQuickly(index);
     528        if (m_isJSArray && m_object->canGetIndexQuickly(index))
     529            value = m_object->getIndexQuickly(index);
    533530        else {
    534531            PropertySlot slot(m_object, PropertySlot::InternalMethodType::Get);
Note: See TracChangeset for help on using the changeset viewer.