Ignore:
Timestamp:
Aug 25, 2011, 4:30:14 PM (14 years ago)
Author:
[email protected]
Message:

Unzip initialization lists and constructors in JSCell hierarchy (1/7)
https://bugs.webkit.org/show_bug.cgi?id=66827

Patch by Mark Hahnenberg <[email protected]> on 2011-08-25
Reviewed by Geoffrey Garen.

Added finishCreation() methods to all immediately subclasses of JSCell with
non-empty constructors. Part of a larger refactoring to "unzip" initialization
lists and constructor bodies. Also renamed JSCell's constructorBody() method
to finishCreation().

  • runtime/Executable.h:

(JSC::ExecutableBase::ExecutableBase):
(JSC::ExecutableBase::constructorBody):

  • runtime/GetterSetter.h:

(JSC::GetterSetter::GetterSetter):

  • runtime/JSAPIValueWrapper.h:

(JSC::JSAPIValueWrapper::constructorBody):
(JSC::JSAPIValueWrapper::JSAPIValueWrapper):

  • runtime/JSCell.h:

(JSC::JSCell::JSCell::JSCell):
(JSC::JSCell::JSCell::constructorBody):

  • runtime/JSObject.h:

(JSC::JSObject::constructorBody):
(JSC::JSObject::JSObject):

  • runtime/JSPropertyNameIterator.h:

(JSC::JSPropertyNameIterator::constructorBody):

  • runtime/JSString.h:

(JSC::RopeBuilder::JSString):
(JSC::RopeBuilder::constructorBody):

  • runtime/RegExp.cpp:

(JSC::RegExp::RegExp):
(JSC::RegExp::constructorBody):

  • runtime/RegExp.h:
  • runtime/ScopeChain.h:

(JSC::ScopeChainNode::ScopeChainNode):
(JSC::ScopeChainNode::constructorBody):

  • runtime/Structure.cpp:

(JSC::Structure::Structure):

  • runtime/StructureChain.cpp:

(JSC::StructureChain::StructureChain):

  • runtime/StructureChain.h:

(JSC::StructureChain::create):
(JSC::StructureChain::constructorBody):

File:
1 edited

Legend:

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

    r93378 r93835  
    191191            , m_fiberCount(0)
    192192        {
    193             ASSERT(!m_value.isNull());
    194             Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());
    195193        }
    196194
     
    202200            , m_fiberCount(0)
    203201        {
    204             ASSERT(!m_value.isNull());
    205             Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());
    206202        }
    207203        JSString(JSGlobalData& globalData, PassRefPtr<StringImpl> value, HasOtherOwnerType)
     
    211207            , m_fiberCount(0)
    212208        {
    213             ASSERT(!m_value.isNull());
    214209        }
    215210        JSString(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope)
     
    218213            , m_fiberCount(1)
    219214        {
    220             m_fibers[0] = rope.leakRef();
    221215        }
    222216        // This constructor constructs a new string by concatenating s1 & s2.
     
    227221            , m_fiberCount(fiberCount)
    228222        {
    229             ASSERT(fiberCount <= s_maxInternalRopeLength);
    230             unsigned index = 0;
    231             appendStringInConstruct(index, s1);
    232             appendStringInConstruct(index, s2);
    233             ASSERT(fiberCount == index);
    234223        }
    235224        // This constructor constructs a new string by concatenating s1 & s2.
     
    240229            , m_fiberCount(fiberCount)
    241230        {
    242             ASSERT(fiberCount <= s_maxInternalRopeLength);
    243             unsigned index = 0;
    244             appendStringInConstruct(index, s1);
    245             appendStringInConstruct(index, u2);
    246             ASSERT(fiberCount == index);
    247231        }
    248232        // This constructor constructs a new string by concatenating s1 & s2.
     
    253237            , m_fiberCount(fiberCount)
    254238        {
     239        }
     240        JSString(ExecState* exec)
     241            : JSCell(exec->globalData(), exec->globalData().stringStructure.get())
     242            , m_length(0)
     243            , m_fiberCount(s_maxInternalRopeLength)
     244        {
     245        }
     246
     247        // This constructor constructs a new string by concatenating u1 & u2.
     248        JSString(JSGlobalData& globalData, const UString& u1, const UString& u2)
     249            : JSCell(globalData, globalData.stringStructure.get())
     250            , m_length(u1.length() + u2.length())
     251            , m_fiberCount(2)
     252        {
     253        }
     254
     255        // This constructor constructs a new string by concatenating u1, u2 & u3.
     256        JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
     257            : JSCell(globalData, globalData.stringStructure.get())
     258            , m_length(u1.length() + u2.length() + u3.length())
     259            , m_fiberCount(s_maxInternalRopeLength)
     260        {
     261        }
     262
     263        void finishCreation(JSGlobalData& globalData, const UString& value)
     264        {
     265            Base::finishCreation(globalData);
     266            ASSERT(!m_value.isNull());
     267            Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());
     268        }
     269
     270        void finishCreation(JSGlobalData& globalData)
     271        {
     272            Base::finishCreation(globalData);
     273            ASSERT(!m_value.isNull());
     274        }
     275
     276        void finishCreation(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope)
     277        {
     278            Base::finishCreation(globalData);
     279            m_fibers[0] = rope.leakRef();
     280        }
     281
     282        void finishCreation(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, JSString* s2)
     283        {
     284            Base::finishCreation(globalData);
    255285            ASSERT(fiberCount <= s_maxInternalRopeLength);
    256286            unsigned index = 0;
    257             appendStringInConstruct(index, u1);
    258             appendStringInConstruct(index, s2);
     287            appendStringInCreate(index, s1);
     288            appendStringInCreate(index, s2);
    259289            ASSERT(fiberCount == index);
    260290        }
    261         // This constructor constructs a new string by concatenating v1, v2 & v3.
     291
     292        void finishCreation(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, const UString& u2)
     293        {
     294            Base::finishCreation(globalData);
     295            ASSERT(fiberCount <= s_maxInternalRopeLength);
     296            unsigned index = 0;
     297            appendStringInCreate(index, s1);
     298            appendStringInCreate(index, u2);
     299            ASSERT(fiberCount == index);
     300        }
     301
     302        void finishCreation(JSGlobalData& globalData, unsigned fiberCount, const UString& u1, JSString* s2)
     303        {
     304            Base::finishCreation(globalData);
     305            ASSERT(fiberCount <= s_maxInternalRopeLength);
     306            unsigned index = 0;
     307            appendStringInCreate(index, u1);
     308            appendStringInCreate(index, s2);
     309            ASSERT(fiberCount == index);
     310        }
     311
     312        // Fills in the new string by concatenating v1, v2 & v3.
    262313        // This should only be called with fiberCount <= 3 ... which since every
    263314        // value must require a fiberCount of at least one implies that the length
    264315        // for each value must be exactly 1!
    265         JSString(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
    266             : JSCell(exec->globalData(), exec->globalData().stringStructure.get())
    267             , m_length(0)
    268             , m_fiberCount(s_maxInternalRopeLength)
    269         {
    270             constructorBody(exec, v1, v2, v3);
    271         }
    272 
    273         // This constructor constructs a new string by concatenating u1 & u2.
    274         JSString(JSGlobalData& globalData, const UString& u1, const UString& u2)
    275             : JSCell(globalData, globalData.stringStructure.get())
    276             , m_length(u1.length() + u2.length())
    277             , m_fiberCount(2)
    278         {
     316        void finishCreation(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
     317        {
     318            Base::finishCreation(exec->globalData());
    279319            unsigned index = 0;
    280             appendStringInConstruct(index, u1);
    281             appendStringInConstruct(index, u2);
     320            appendValueInCreateAndIncrementLength(exec, index, v1);
     321            appendValueInCreateAndIncrementLength(exec, index, v2);
     322            appendValueInCreateAndIncrementLength(exec, index, v3);
     323            ASSERT(index == s_maxInternalRopeLength);
     324        }
     325
     326        void finishCreation(JSGlobalData& globalData, const UString& u1, const UString& u2)
     327        {
     328            Base::finishCreation(globalData);
     329            unsigned index = 0;
     330            appendStringInCreate(index, u1);
     331            appendStringInCreate(index, u2);
    282332            ASSERT(index <= s_maxInternalRopeLength);
    283333        }
    284334
    285         // This constructor constructs a new string by concatenating u1, u2 & u3.
    286         JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
    287             : JSCell(globalData, globalData.stringStructure.get())
    288             , m_length(u1.length() + u2.length() + u3.length())
    289             , m_fiberCount(s_maxInternalRopeLength)
    290         {
     335        void finishCreation(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
     336        {
     337            Base::finishCreation(globalData);
    291338            unsigned index = 0;
    292             appendStringInConstruct(index, u1);
    293             appendStringInConstruct(index, u2);
    294             appendStringInConstruct(index, u3);
     339            appendStringInCreate(index, u1);
     340            appendStringInCreate(index, u2);
     341            appendStringInCreate(index, u3);
    295342            ASSERT(index <= s_maxInternalRopeLength);
    296         }
    297 
    298     protected:
    299         void constructorBody(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
    300         {
    301             unsigned index = 0;
    302             appendValueInConstructAndIncrementLength(exec, index, v1);
    303             appendValueInConstructAndIncrementLength(exec, index, v2);
    304             appendValueInConstructAndIncrementLength(exec, index, v3);
    305             ASSERT(index == s_maxInternalRopeLength);
    306343        }
    307344
     
    309346        static JSString* create(JSGlobalData& globalData, const UString& value)
    310347        {
    311             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value);
     348            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value);
     349            newString->finishCreation(globalData, value);
     350            return newString;
    312351        }
    313352        static JSString* createHasOtherOwner(JSGlobalData& globalData, const UString& value)
    314353        {
    315             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner);
     354            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner);
     355            newString->finishCreation(globalData, value);
     356            return newString;
    316357        }
    317358        static JSString* createHasOtherOwner(JSGlobalData& globalData, PassRefPtr<StringImpl> value)
    318359        {
    319             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner);
     360            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner);
     361            newString->finishCreation(globalData);
     362            return newString;
    320363        }
    321364        static JSString* create(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope)
    322365        {
    323             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, rope);
     366            RefPtr<RopeImpl> tempRope = rope;
     367            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, tempRope);
     368            newString->finishCreation(globalData, tempRope);
     369            return newString;
    324370        }
    325371        static JSString* create(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, JSString* s2)
    326372        {
    327             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, s2);
     373            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, s2);
     374            newString->finishCreation(globalData, fiberCount, s1, s2);
     375            return newString;
    328376        }
    329377        static JSString* create(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, const UString& u2)
    330378        {
    331             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, u2);
     379            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, u2);
     380            newString->finishCreation(globalData, fiberCount, s1, u2);
     381            return newString;
    332382        }
    333383        static JSString* create(JSGlobalData& globalData, unsigned fiberCount, const UString& u1, JSString* s2)
    334384        {
    335             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, u1, s2);
     385            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, u1, s2);
     386            newString->finishCreation(globalData, fiberCount, u1, s2);
     387            return newString;
    336388        }
    337389        static JSString* create(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
    338390        {
    339             return new (allocateCell<JSString>(*exec->heap())) JSString(exec, v1, v2, v3);
     391            JSString* newString = new (allocateCell<JSString>(*exec->heap())) JSString(exec);
     392            newString->finishCreation(exec, v1, v2, v3);
     393            return newString;
    340394        }
    341395        static JSString* create(JSGlobalData& globalData, const UString& u1, const UString& u2)
    342396        {
    343             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2);
     397            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2);
     398            newString->finishCreation(globalData, u1, u2);
     399            return newString;
    344400        }
    345401        static JSString* create(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
    346402        {
    347             return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2, u3);
     403            JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2, u3);
     404            newString->finishCreation(globalData, u1, u2, u3);
     405            return newString;
    348406        }
    349407
     
    398456        JSString* substringFromRope(ExecState*, unsigned offset, unsigned length);
    399457
    400         void appendStringInConstruct(unsigned& index, const UString& string)
     458        void appendStringInCreate(unsigned& index, const UString& string)
    401459        {
    402460            StringImpl* impl = string.impl();
     
    406464        }
    407465
    408         void appendStringInConstruct(unsigned& index, JSString* jsString)
     466        void appendStringInCreate(unsigned& index, JSString* jsString)
    409467        {
    410468            if (jsString->isRope()) {
     
    415473                }
    416474            } else
    417                 appendStringInConstruct(index, jsString->string());
    418         }
    419 
    420         void appendValueInConstructAndIncrementLength(ExecState* exec, unsigned& index, JSValue v)
     475                appendStringInCreate(index, jsString->string());
     476        }
     477
     478        void appendValueInCreateAndIncrementLength(ExecState* exec, unsigned& index, JSValue v)
    421479        {
    422480            if (v.isString()) {
     
    424482                JSString* s = static_cast<JSString*>(v.asCell());
    425483                ASSERT(s->fiberCount() == 1);
    426                 appendStringInConstruct(index, s);
     484                appendStringInCreate(index, s);
    427485                m_length += s->length();
    428486            } else {
Note: See TracChangeset for help on using the changeset viewer.