Ignore:
Timestamp:
Jul 13, 2010, 5:29:32 PM (15 years ago)
Author:
[email protected]
Message:

2010-07-13 Andreas Kling <[email protected]>

Reviewed by Darin Adler.

Avoid slow-path for put() in Array.splice()
https://bugs.webkit.org/show_bug.cgi?id=41920

Defer creation of the returned array until its final size is known
to avoid growing it while adding elements.

  • runtime/JSArray.cpp: (JSC::JSArray::JSArray): Add two modes of creation, CreateInitialized (old) and CreateCompact (which should only be used when constructing arrays whose size and contents are known at the time of creation.) (JSC::JSArray::setLength): Skip first consistency check if in CreateCompact initialization mode. (Only applies to non-empty arrays.) (JSC::JSArray::checkConsistency): Build fix (JSValue::type() is gone)
  • runtime/JSArray.h: (JSC::JSArray::uncheckedSetIndex): Added for fast initialization of compact arrays. Does no bounds or other sanity checking.
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSplice): Optimized creation of the returned JSArray.
  • runtime/ArrayConstructor.cpp: (JSC::constructArrayWithSizeQuirk): Pass CreateInitialized to ctor.
  • runtime/JSGlobalObject.h: (JSC::constructEmptyArray): Pass CreateInitialized to ctor.
  • runtime/RegExpConstructor.cpp: (JSC::RegExpMatchesArray::RegExpMatchesArray): Pass CreateInitialized to ctor.
File:
1 edited

Legend:

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

    r55262 r63268  
    2323
    2424#include "JSObject.h"
     25
     26#define CHECK_ARRAY_CONSISTENCY 0
    2527
    2628namespace JSC {
     
    3436        void* subclassData; // A JSArray subclass can use this to fill the vector lazily.
    3537        size_t reportedMapCapacity;
     38#if CHECK_ARRAY_CONSISTENCY
     39        bool m_inCompactInitialization;
     40#endif
    3641        JSValue m_vector[1];
    3742    };
     43
     44    // The CreateCompact creation mode is used for fast construction of arrays
     45    // whose size and contents are known at time of creation.
     46    //
     47    // There are two obligations when using this mode:
     48    //
     49    //   - uncheckedSetIndex() must be used when initializing the array.
     50    //   - setLength() must be called after initialization.
     51
     52    enum ArrayCreationMode { CreateCompact, CreateInitialized };
    3853
    3954    class JSArray : public JSObject {
     
    4358    public:
    4459        explicit JSArray(NonNullPassRefPtr<Structure>);
    45         JSArray(NonNullPassRefPtr<Structure>, unsigned initialLength);
     60        JSArray(NonNullPassRefPtr<Structure>, unsigned initialLength, ArrayCreationMode);
    4661        JSArray(NonNullPassRefPtr<Structure>, const ArgList& initialValues);
    4762        virtual ~JSArray();
     
    8297            }
    8398            x = v;
     99        }
     100
     101        void uncheckedSetIndex(unsigned i, JSValue v)
     102        {
     103            ASSERT(canSetIndex(i));
     104#if CHECK_ARRAY_CONSISTENCY
     105            ASSERT(m_storage->m_inCompactInitialization);
     106#endif
     107            m_storage->m_vector[i] = v;
    84108        }
    85109
Note: See TracChangeset for help on using the changeset viewer.