Ignore:
Timestamp:
Dec 7, 2010, 3:11:08 AM (14 years ago)
Author:
Antti Koivisto
Message:

https://bugs.webkit.org/show_bug.cgi?id=50412
http://www.wunderground.com/US/CA/Hayward.html causes big memory spike during page loading

Reviewed by Gavin Barraclough.

Creating a substring caused the original string be flattened if it was in the rope form. This could use
significant amount of memory by reducing buffer sharing between strings.

Add a rope specific substring function that constructs the substring by reusing the rope fibers
instead of flattening the rope.

No change observed in SunSpider.

  • runtime/JSString.cpp:

(JSC::JSString::substringFromRope):

  • runtime/JSString.h:

(JSC::jsSubstring):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncSubstr):
(JSC::stringProtoFuncSubstring):

File:
1 edited

Legend:

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

    r71375 r73433  
    357357
    358358        void resolveRope(ExecState*) const;
     359        JSString* substringFromRope(ExecState*, unsigned offset, unsigned length);
    359360
    360361        void appendStringInConstruct(unsigned& index, const UString& string)
     
    436437        friend JSValue jsString(ExecState* exec, JSValue thisValue);
    437438        friend JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);
     439        friend JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length);
    438440    };
    439441
     
    519521        JSGlobalData* globalData = &exec->globalData();
    520522        return fixupVPtr(globalData, new (globalData) JSString(globalData, s, callback, context));
     523    }
     524   
     525    inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length)
     526    {
     527        ASSERT(offset <= static_cast<unsigned>(s->length()));
     528        ASSERT(length <= static_cast<unsigned>(s->length()));
     529        ASSERT(offset + length <= static_cast<unsigned>(s->length()));
     530        JSGlobalData* globalData = &exec->globalData();
     531        if (!length)
     532            return globalData->smallStrings.emptyString(globalData);
     533        if (s->isRope())
     534            return s->substringFromRope(exec, offset, length);
     535        return jsSubstring(globalData, s->m_value, offset, length);
    521536    }
    522537
Note: See TracChangeset for help on using the changeset viewer.