source: webkit/trunk/JavaScriptCore/kjs/JSArray.h@ 36778

Last change on this file since 36778 was 36778, checked in by Darin Adler, 17 years ago

2008-09-22 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

3% or so speedup on DeltaBlue benchmark.

  • kjs/ArrayPrototype.cpp: (JSC::arrayProtoFuncPop): Call JSArray::pop when appropriate. (JSC::arrayProtoFuncPush): Call JSArray::push when appropriate.
  • kjs/JSArray.cpp: (JSC::JSArray::putSlowCase): Set m_fastAccessCutoff when appropriate, getting us into the fast code path. (JSC::JSArray::pop): Added. (JSC::JSArray::push): Added.
  • kjs/JSArray.h: Added push and pop.
  • kjs/operations.cpp: (JSC::throwOutOfMemoryError): Don't inline this. Helps us avoid PIC branches.
  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#ifndef JSArray_h
22#define JSArray_h
23
24#include "JSObject.h"
25
26namespace JSC {
27
28 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap;
29
30 struct ArrayStorage {
31 unsigned m_length;
32 unsigned m_vectorLength;
33 unsigned m_numValuesInVector;
34 SparseArrayValueMap* m_sparseValueMap;
35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily.
36 JSValue* m_vector[1];
37 };
38
39 class JSArray : public JSObject {
40 friend class CTI;
41
42 public:
43 explicit JSArray(PassRefPtr<StructureID>);
44 JSArray(PassRefPtr<StructureID>, unsigned initialLength);
45 JSArray(ExecState*, PassRefPtr<StructureID>, const ArgList& initialValues);
46 virtual ~JSArray();
47
48 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
49 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
50 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem.
51
52 static const ClassInfo info;
53
54 unsigned length() const { return m_storage->m_length; }
55 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray.
56
57 void sort(ExecState*);
58 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&);
59
60 void push(ExecState*, JSValue*);
61 JSValue* pop();
62
63 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; }
64 JSValue* getIndex(unsigned i)
65 {
66 ASSERT(canGetIndex(i));
67 return m_storage->m_vector[i];
68 }
69
70 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; }
71 JSValue* setIndex(unsigned i, JSValue* v)
72 {
73 ASSERT(canSetIndex(i));
74 return m_storage->m_vector[i] = v;
75 }
76
77 protected:
78 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, PutPropertySlot&);
79 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
80 virtual bool deleteProperty(ExecState*, unsigned propertyName);
81 virtual void getPropertyNames(ExecState*, PropertyNameArray&);
82 virtual void mark();
83
84 void* lazyCreationData();
85 void setLazyCreationData(void*);
86
87 private:
88 virtual const ClassInfo* classInfo() const { return &info; }
89
90 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&);
91 void putSlowCase(ExecState*, unsigned propertyName, JSValue*);
92
93 bool increaseVectorLength(unsigned newLength);
94
95 unsigned compactForSorting();
96
97 enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck };
98 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck);
99
100 unsigned m_fastAccessCutoff;
101 ArrayStorage* m_storage;
102 };
103
104 JSArray* constructEmptyArray(ExecState*);
105 JSArray* constructEmptyArray(ExecState*, unsigned initialLength);
106 JSArray* constructArray(ExecState*, JSValue* singleItemValue);
107 JSArray* constructArray(ExecState*, const ArgList& values);
108
109} // namespace JSC
110
111#endif // JSArray_h
Note: See TracBrowser for help on using the repository browser.