Ignore:
Timestamp:
Nov 24, 2009, 1:41:53 PM (16 years ago)
Author:
[email protected]
Message:

JSON.stringify performance on undefined is very poor
https://bugs.webkit.org/show_bug.cgi?id=31839

Reviewed by Alexey Proskuryakov.

Switch from a UString to a Vector<UChar> when building
the JSON string, allowing us to safely remove the substr-copy
we otherwise did when unwinding an undefined property.

Also turns out to be a ~5% speedup on stringification.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r47857 r51352  
    7171
    7272private:
    73     typedef UString StringBuilder;
     73    class StringBuilder : public Vector<UChar> {
     74    public:
     75        using Vector<UChar>::append;
     76
     77        inline void append(const char* str)
     78        {
     79            size_t len = strlen(str);
     80            reserveCapacity(size() + len);
     81            for (size_t i = 0; i < len; i++)
     82                Vector<UChar>::append(str[i]);
     83        }
     84
     85        inline void append(const UString& str)
     86        {
     87            append(str.data(), str.size());
     88        }
     89    };
    7490
    7591    class Holder {
     
    270286        return jsNull();
    271287
    272     return jsString(m_exec, result);
     288    result.shrinkToFit();
     289    size_t length = result.size();
     290    return jsString(m_exec, UString(result.releaseBuffer(), length, false));
    273291}
    274292
     
    587605            // In this case we don't want the separator and property name that we
    588606            // already appended, so roll back.
    589             builder = builder.substr(0, rollBackPoint);
     607            builder.resize(rollBackPoint);
    590608            break;
    591609    }
Note: See TracChangeset for help on using the changeset viewer.