Changeset 43432 in webkit for trunk/JavaScriptCore/runtime/JSObject.h
- Timestamp:
- May 9, 2009, 1:35:57 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSObject.h
r43153 r43432 52 52 }; 53 53 54 typedef JSValue* PropertyStorage; 54 typedef EncodedJSValue* PropertyStorage; 55 typedef EncodedJSValue const * ConstPropertyStorage; 55 56 56 57 class JSObject : public JSCell { … … 76 77 Structure* inheritorID(); 77 78 78 PropertyStorage& propertyStorage() { return m_propertyStorage; } 79 ConstPropertyStorage propertyStorage() const { return (isUsingInlineStorage() ? m_inlineStorage : m_externalStorage); } 80 PropertyStorage propertyStorage() { return (isUsingInlineStorage() ? m_inlineStorage : m_externalStorage); } 79 81 80 82 virtual UString className() const; … … 126 128 { 127 129 size_t offset = m_structure->get(propertyName); 128 return offset != WTF::notFound ? m_propertyStorage[offset] : JSValue(); 130 return offset != WTF::notFound ? getDirectOffset(offset) : JSValue(); 131 } 132 133 size_t getOffset(const Identifier& propertyName) 134 { 135 return m_structure->get(propertyName); 129 136 } 130 137 … … 141 148 } 142 149 143 size_t offsetForLocation(JSValue* location) 144 { 145 return location - m_propertyStorage; 150 size_t offsetForLocation(JSValue* location) const 151 { 152 return location - reinterpret_cast<JSValue const *>(propertyStorage()); 153 } 154 155 JSValue const * locationForOffset(size_t offset) const 156 { 157 return reinterpret_cast<JSValue const *>(&propertyStorage()[offset]); 146 158 } 147 159 148 160 JSValue* locationForOffset(size_t offset) 149 161 { 150 return &m_propertyStorage[offset];162 return reinterpret_cast<JSValue*>(&propertyStorage()[offset]); 151 163 } 152 164 … … 164 176 165 177 // Fast access to known property offsets. 166 JSValue getDirectOffset(size_t offset) { return m_propertyStorage[offset]; }167 void putDirectOffset(size_t offset, JSValue value) { m_propertyStorage[offset] = value; }178 JSValue getDirectOffset(size_t offset) const { return JSValue::decode(propertyStorage()[offset]); } 179 void putDirectOffset(size_t offset, JSValue value) { propertyStorage()[offset] = JSValue::encode(value); } 168 180 169 181 void fillGetterPropertySlot(PropertySlot&, JSValue* location); … … 182 194 void allocatePropertyStorage(size_t oldSize, size_t newSize); 183 195 void allocatePropertyStorageInline(size_t oldSize, size_t newSize); 184 bool usingInlineStorage() const { return m_propertyStorage == m_inlineStorage; }185 186 static const size_t inlineStorageCapacity = 2;196 bool isUsingInlineStorage() const { return m_structure->isUsingInlineStorage(); } 197 198 static const size_t inlineStorageCapacity = 3; 187 199 static const size_t nonInlineBaseStorageCapacity = 16; 188 200 … … 203 215 RefPtr<Structure> m_inheritorID; 204 216 205 PropertyStorage m_propertyStorage; 206 JSValue m_inlineStorage[inlineStorageCapacity]; 217 union { 218 PropertyStorage m_externalStorage; 219 EncodedJSValue m_inlineStorage[inlineStorageCapacity]; 220 }; 207 221 }; 208 222 … … 219 233 inline JSObject::JSObject(PassRefPtr<Structure> structure) 220 234 : JSCell(structure.releaseRef()) // ~JSObject balances this ref() 221 , m_propertyStorage(m_inlineStorage)222 235 { 223 236 ASSERT(m_structure); … … 230 243 { 231 244 ASSERT(m_structure); 232 if ( m_propertyStorage != m_inlineStorage)233 delete [] m_ propertyStorage;245 if (!isUsingInlineStorage()) 246 delete [] m_externalStorage; 234 247 m_structure->deref(); 235 248 } … … 258 271 return m_inheritorID.get(); 259 272 return createInheritorID(); 273 } 274 275 inline bool Structure::isUsingInlineStorage() const 276 { 277 return (propertyStorageCapacity() == JSObject::inlineStorageCapacity); 260 278 } 261 279 … … 395 413 if (checkReadOnly && currentAttributes & ReadOnly) 396 414 return; 397 m_propertyStorage[offset] = value;415 putDirectOffset(offset, value); 398 416 slot.setExistingProperty(this, offset); 399 417 return; … … 406 424 407 425 ASSERT(offset < m_structure->propertyStorageCapacity()); 408 m_propertyStorage[offset] = value;426 putDirectOffset(offset, value); 409 427 slot.setNewProperty(this, offset); 410 428 return; … … 418 436 419 437 ASSERT(offset < structure->propertyStorageCapacity()); 420 m_propertyStorage[offset] = value; 438 setStructure(structure.release()); 439 putDirectOffset(offset, value); 421 440 slot.setNewProperty(this, offset); 422 441 slot.setWasTransition(true); 423 setStructure(structure.release());424 442 return; 425 443 } … … 430 448 if (checkReadOnly && currentAttributes & ReadOnly) 431 449 return; 432 m_propertyStorage[offset] = value;450 putDirectOffset(offset, value); 433 451 slot.setExistingProperty(this, offset); 434 452 return; … … 440 458 441 459 ASSERT(offset < structure->propertyStorageCapacity()); 442 m_propertyStorage[offset] = value; 460 setStructure(structure.release()); 461 putDirectOffset(offset, value); 443 462 slot.setNewProperty(this, offset); 444 463 slot.setWasTransition(true); 445 setStructure(structure.release());446 464 } 447 465 … … 452 470 if (currentCapacity != m_structure->propertyStorageCapacity()) 453 471 allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity()); 454 m_propertyStorage[offset] = value;472 putDirectOffset(offset, value); 455 473 } 456 474 … … 541 559 ASSERT(newSize > oldSize); 542 560 543 JSValue* oldPropertyStorage = m_propertyStorage; 544 m_propertyStorage = new JSValue[newSize]; 561 // It's important that this function not rely on m_structure, since 562 // we might be in the middle of a transition. 563 bool wasInline = (oldSize == JSObject::inlineStorageCapacity); 564 565 PropertyStorage oldPropertyStorage = (wasInline ? m_inlineStorage : m_externalStorage); 566 PropertyStorage newPropertyStorage = new EncodedJSValue[newSize]; 545 567 546 568 for (unsigned i = 0; i < oldSize; ++i) 547 m_propertyStorage[i] = oldPropertyStorage[i];548 549 if ( oldPropertyStorage != m_inlineStorage)569 newPropertyStorage[i] = oldPropertyStorage[i]; 570 571 if (!wasInline) 550 572 delete [] oldPropertyStorage; 573 574 m_externalStorage = newPropertyStorage; 551 575 } 552 576
Note:
See TracChangeset
for help on using the changeset viewer.