Changeset 64184 in webkit for trunk/JavaScriptCore/runtime/JSArray.h
- Timestamp:
- Jul 27, 2010, 5:36:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSArray.h
r64177 r64184 30 30 typedef HashMap<unsigned, JSValue> SparseArrayValueMap; 31 31 32 // This struct holds the actual data values of an array. A JSArray object points to it's contained ArrayStorage33 // struct by pointing to m_vector. To access the contained ArrayStorage struct, use the getStorage() and34 // setStorage() methods. It is important to note that there may be space before the ArrayStorage that35 // is used to quick unshift / shift operation. The actual allocated pointer is available by using:36 // getStorage() - m_indexBias * sizeof(JSValue)37 32 struct ArrayStorage { 38 unsigned m_length; // The "length" property on the array33 unsigned m_length; 39 34 unsigned m_numValuesInVector; 40 35 SparseArrayValueMap* m_sparseValueMap; … … 73 68 74 69 static JS_EXPORTDATA const ClassInfo info; 75 76 unsigned length() const { return arrayStorage()->m_length; }70 71 unsigned length() const { return m_storage->m_length; } 77 72 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. 78 73 … … 84 79 JSValue pop(); 85 80 86 void shiftCount(ExecState*, int count); 87 void unshiftCount(ExecState*, int count); 88 89 bool canGetIndex(unsigned i) { return i < m_vectorLength && m_vector[i]; } 81 bool canGetIndex(unsigned i) { return i < m_vectorLength && m_storage->m_vector[i]; } 90 82 JSValue getIndex(unsigned i) 91 83 { 92 84 ASSERT(canGetIndex(i)); 93 return m_ vector[i];85 return m_storage->m_vector[i]; 94 86 } 95 87 … … 98 90 { 99 91 ASSERT(canSetIndex(i)); 100 101 JSValue& x = m_vector[i]; 92 JSValue& x = m_storage->m_vector[i]; 102 93 if (!x) { 103 ArrayStorage *storage = arrayStorage(); 104 ++storage->m_numValuesInVector; 105 if (i >= storage->m_length) 106 storage->m_length = i + 1; 94 ++m_storage->m_numValuesInVector; 95 if (i >= m_storage->m_length) 96 m_storage->m_length = i + 1; 107 97 } 108 98 x = v; 109 99 } 110 100 111 101 void uncheckedSetIndex(unsigned i, JSValue v) 112 102 { 113 103 ASSERT(canSetIndex(i)); 114 ArrayStorage *storage = arrayStorage();115 104 #if CHECK_ARRAY_CONSISTENCY 116 ASSERT( storage->m_inCompactInitialization);105 ASSERT(m_storage->m_inCompactInitialization); 117 106 #endif 118 storage->m_vector[i] = v;107 m_storage->m_vector[i] = v; 119 108 } 120 109 … … 139 128 void* subclassData() const; 140 129 void setSubclassData(void*); 141 142 inline ArrayStorage *arrayStorage() const143 {144 return reinterpret_cast<ArrayStorage*>(reinterpret_cast<char*>(m_vector) - (sizeof(ArrayStorage) - sizeof(JSValue)));145 }146 147 inline void setArrayStorage(ArrayStorage *storage)148 {149 m_vector = &storage->m_vector[0];150 }151 130 152 131 private: … … 156 135 void putSlowCase(ExecState*, unsigned propertyName, JSValue); 157 136 158 unsigned getNewVectorLength(unsigned desiredLength);159 137 bool increaseVectorLength(unsigned newLength); 160 bool increaseVectorPrefixLength(unsigned newLength);161 138 162 139 unsigned compactForSorting(); … … 165 142 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck); 166 143 167 unsigned m_vectorLength; // The valid length of m_vector 168 int m_indexBias; // The number of JSValue sized blocks before ArrayStorage. 169 JSValue* m_vector; // Copy of ArrayStorage.m_vector. Used for quick vector access and to materialize ArrayStorage ptr. 144 unsigned m_vectorLength; 145 ArrayStorage* m_storage; 170 146 }; 171 147 … … 193 169 JSObject::markChildrenDirect(markStack); 194 170 195 ArrayStorage* storage = arrayStorage();171 ArrayStorage* storage = m_storage; 196 172 197 173 unsigned usedVectorLength = std::min(storage->m_length, m_vectorLength);
Note:
See TracChangeset
for help on using the changeset viewer.