Ignore:
Timestamp:
Oct 22, 2007, 6:35:17 AM (18 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed by Maciej.

Makes the morph test in SunSpider 26% faster, and the overall
benchmark 3% faster.

This also fixes some small problems we had with the distinction
between nonexistent and undefined values in arrays.

  • kjs/array_instance.h: Tweaked formatting and naming.
  • kjs/array_instance.cpp: Copied from kjs/array_object.cpp. (KJS::storageSize): Added. Computes the size of the storage given a vector length. (KJS::increasedVectorLength): Added. Implements the rule for resizing the vector. (KJS::isDenseEnoughForVector): Added. (KJS::ArrayInstance::ArrayInstance): Initialize the new fields. (KJS::ArrayInstance::~ArrayInstance): Since m_storage is now never 0, delete it. (KJS::ArrayInstance::getItem): Updated for name changes. (KJS::ArrayInstance::lengthGetter): Ditto. (KJS::ArrayInstance::inlineGetOwnPropertySlot): Added. Allows both versions of getOwnPropertySlot to share more code. (KJS::ArrayInstance::getOwnPropertySlot): Just refactored, no code change. (KJS::ArrayInstance::put): Added logic for extending the vector as long as the array is dense enough. Also keep m_numValuesInVector up to date. (KJS::ArrayInstance::deleteProperty): Added code to keep m_numValuesInVector up to date. (KJS::ArrayInstance::getPropertyNames): Fixed bug where this would omit names for array indices with undefined values. (KJS::ArrayInstance::increaseVectorLength): Renamed from resizeStorage. Also simplified to only handle getting larger. (KJS::ArrayInstance::setLength): Added code to update m_numValuesInVector, to zero out the unused part of the vector and to delete the map if it's no longer needed. (KJS::ArrayInstance::mark): Tweaked formatting. (KJS::compareByStringForQSort): Ditto. (KJS::ArrayInstance::sort): Ditto. (KJS::CompareWithCompareFunctionArguments::CompareWithCompareFunctionArguments): Ditto. (KJS::compareWithCompareFunctionForQSort): Ditto. (KJS::ArrayInstance::compactForSorting): Fixed bug where this would turn undefined values into nonexistent values in some cases.
  • kjs/array_object.h: Removed MAX_ARRAY_INDEX.
  • kjs/array_object.cpp: Removed ArrayInstance. Moved to a separate file.

LayoutTests:

  • fast/js/kde/resources/Array.js: Added tests to cover missing value behavior (not the same as undefined values in arrays). This matches the ECMA JavaScript specification, but doesn't exactly match Firefox.
  • fast/js/kde/Array-expected.txt: Updated with results.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_instance.h

    r26850 r26881  
    11// -*- c-basic-offset: 2 -*-
    22/*
    3  *  This file is part of the KDE libraries
    43 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    54 *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
     
    2827namespace KJS {
    2928
     29  struct ArrayStorage;
     30
    3031  class ArrayInstance : public JSObject {
    3132  public:
    32     ArrayInstance(JSObject *proto, unsigned initialLength);
    33     ArrayInstance(JSObject *proto, const List &initialValues);
     33    ArrayInstance(JSObject* prototype, unsigned initialLength);
     34    ArrayInstance(JSObject* prototype, const List& initialValues);
    3435    ~ArrayInstance();
    3536
    36     virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
    37     virtual bool getOwnPropertySlot(ExecState *, unsigned, PropertySlot&);
    38     virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
    39     virtual void put(ExecState *exec, unsigned propertyName, JSValue *value, int attr = None);
    40     virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    41     virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
     37    virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     38    virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
     39    virtual void put(ExecState*, const Identifier& propertyName, JSValue*, int attributes = None);
     40    virtual void put(ExecState*, unsigned propertyName, JSValue*, int attributes = None);
     41    virtual bool deleteProperty(ExecState *, const Identifier& propertyName);
     42    virtual bool deleteProperty(ExecState *, unsigned propertyName);
    4243    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    4344
    4445    virtual void mark();
    4546
    46     virtual const ClassInfo *classInfo() const { return &info; }
     47    virtual const ClassInfo* classInfo() const { return &info; }
    4748    static const ClassInfo info;
     49
     50    unsigned getLength() const { return m_length; }
     51    JSValue* getItem(unsigned) const;
     52
     53    void sort(ExecState*);
     54    void sort(ExecState*, JSObject* compareFunction);
     55
     56  private:
     57    static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
     58    bool inlineGetOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
     59
     60    void setLength(unsigned);
     61    void increaseVectorLength(unsigned newLength);
    4862   
    49     unsigned getLength() const { return length; }
    50     JSValue* getItem(unsigned) const;
    51    
    52     void sort(ExecState *exec);
    53     void sort(ExecState *exec, JSObject *compareFunction);
    54    
    55   private:
    56     static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
     63    unsigned compactForSorting();   
    5764
    58     void setLength(unsigned newLength);
    59    
    60     unsigned compactForSorting();
    61    
    62     void resizeStorage(unsigned);
    63 
    64     // store capacity in extra space at the beginning of the storage array to save space
    65     size_t capacity() { return storage ? reinterpret_cast<size_t>(storage[-1]) : 0; }
    66 
    67     unsigned length;
    68     unsigned storageLength;
    69     JSValue **storage;
     65    unsigned m_length;
     66    unsigned m_vectorLength;
     67    ArrayStorage* m_storage;
    7068  };
    7169
Note: See TracChangeset for help on using the changeset viewer.