Changeset 44076 in webkit for trunk/JavaScriptCore/runtime/Structure.cpp
- Timestamp:
- May 22, 2009, 6:48:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Structure.cpp
r43122 r44076 124 124 : m_typeInfo(typeInfo) 125 125 , m_prototype(prototype) 126 , m_specificValueInPrevious(0) 126 127 , m_propertyTable(0) 127 128 , m_propertyStorageCapacity(JSObject::inlineStorageCapacity) … … 159 160 m_previous->m_transitions.singleTransition = 0; 160 161 } else { 161 ASSERT(m_previous->m_transitions.table->contains(make_pair(m_nameInPrevious.get(), m _attributesInPrevious)));162 m_previous->m_transitions.table->remove(make_pair(m_nameInPrevious.get(), m _attributesInPrevious));162 ASSERT(m_previous->m_transitions.table->contains(make_pair(m_nameInPrevious.get(), make_pair(m_attributesInPrevious, m_specificValueInPrevious)))); 163 m_previous->m_transitions.table->remove(make_pair(m_nameInPrevious.get(), make_pair(m_attributesInPrevious, m_specificValueInPrevious))); 163 164 } 164 165 } … … 280 281 structure = structures[i]; 281 282 structure->m_nameInPrevious->ref(); 282 PropertyMapEntry entry(structure->m_nameInPrevious.get(), structure->m_offset, structure->m_attributesInPrevious, ++m_propertyTable->lastIndexUsed);283 PropertyMapEntry entry(structure->m_nameInPrevious.get(), structure->m_offset, structure->m_attributesInPrevious, structure->m_specificValueInPrevious, ++m_propertyTable->lastIndexUsed); 283 284 insertIntoPropertyMapHashTable(entry); 284 285 } … … 327 328 } 328 329 329 PassRefPtr<Structure> Structure::addPropertyTransitionToExistingStructure(Structure* structure, const Identifier& propertyName, unsigned attributes, size_t& offset)330 PassRefPtr<Structure> Structure::addPropertyTransitionToExistingStructure(Structure* structure, const Identifier& propertyName, unsigned attributes, JSCell* specificValue, size_t& offset) 330 331 { 331 332 ASSERT(!structure->m_isDictionary); … … 334 335 if (structure->m_usingSingleTransitionSlot) { 335 336 Structure* existingTransition = structure->m_transitions.singleTransition; 336 if (existingTransition && existingTransition->m_nameInPrevious.get() == propertyName.ustring().rep() && existingTransition->m_attributesInPrevious == attributes) { 337 if (existingTransition && existingTransition->m_nameInPrevious.get() == propertyName.ustring().rep() 338 && existingTransition->m_attributesInPrevious == attributes 339 && existingTransition->m_specificValueInPrevious == specificValue) { 340 337 341 ASSERT(structure->m_transitions.singleTransition->m_offset != noOffset); 338 342 offset = structure->m_transitions.singleTransition->m_offset; … … 340 344 } 341 345 } else { 342 if (Structure* existingTransition = structure->m_transitions.table->get(make_pair(propertyName.ustring().rep(), attributes))) {346 if (Structure* existingTransition = structure->m_transitions.table->get(make_pair(propertyName.ustring().rep(), make_pair(attributes, specificValue)))) { 343 347 ASSERT(existingTransition->m_offset != noOffset); 344 348 offset = existingTransition->m_offset; … … 350 354 } 351 355 352 PassRefPtr<Structure> Structure::addPropertyTransition(Structure* structure, const Identifier& propertyName, unsigned attributes, size_t& offset)356 PassRefPtr<Structure> Structure::addPropertyTransition(Structure* structure, const Identifier& propertyName, unsigned attributes, JSCell* specificValue, size_t& offset) 353 357 { 354 358 ASSERT(!structure->m_isDictionary); 355 359 ASSERT(structure->typeInfo().type() == ObjectType); 356 ASSERT(!Structure::addPropertyTransitionToExistingStructure(structure, propertyName, attributes, offset));360 ASSERT(!Structure::addPropertyTransitionToExistingStructure(structure, propertyName, attributes, specificValue, offset)); 357 361 358 362 if (structure->transitionCount() > s_maxTransitionLength) { 359 363 RefPtr<Structure> transition = toDictionaryTransition(structure); 360 offset = transition->put(propertyName, attributes );364 offset = transition->put(propertyName, attributes, specificValue); 361 365 if (transition->propertyStorageSize() > transition->propertyStorageCapacity()) 362 366 transition->growPropertyStorageCapacity(); … … 365 369 366 370 RefPtr<Structure> transition = create(structure->m_prototype, structure->typeInfo()); 371 367 372 transition->m_cachedPrototypeChain = structure->m_cachedPrototypeChain; 368 373 transition->m_previous = structure; 369 374 transition->m_nameInPrevious = propertyName.ustring().rep(); 370 375 transition->m_attributesInPrevious = attributes; 376 transition->m_specificValueInPrevious = specificValue; 371 377 transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity; 372 378 transition->m_hasGetterSetterProperties = structure->m_hasGetterSetterProperties; … … 386 392 } 387 393 388 offset = transition->put(propertyName, attributes );394 offset = transition->put(propertyName, attributes, specificValue); 389 395 if (transition->propertyStorageSize() > transition->propertyStorageCapacity()) 390 396 transition->growPropertyStorageCapacity(); … … 402 408 StructureTransitionTable* transitionTable = new StructureTransitionTable; 403 409 structure->m_transitions.table = transitionTable; 404 transitionTable->add(make_pair(existingTransition->m_nameInPrevious.get(), existingTransition->m_attributesInPrevious), existingTransition);405 } 406 structure->m_transitions.table->add(make_pair(propertyName.ustring().rep(), attributes), transition.get());410 transitionTable->add(make_pair(existingTransition->m_nameInPrevious.get(), make_pair(existingTransition->m_attributesInPrevious, existingTransition->m_specificValueInPrevious)), existingTransition); 411 } 412 structure->m_transitions.table->add(make_pair(propertyName.ustring().rep(), make_pair(attributes, specificValue)), transition.get()); 407 413 return transition.release(); 408 414 } … … 431 437 transition->m_propertyTable = structure->copyPropertyTable(); 432 438 transition->m_isPinnedPropertyTable = true; 439 440 return transition.release(); 441 } 442 443 PassRefPtr<Structure> Structure::changeFunctionTransition(Structure* structure, const Identifier& replaceFunction) 444 { 445 RefPtr<Structure> transition = create(structure->storedPrototype(), structure->typeInfo()); 446 447 transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity; 448 transition->m_hasGetterSetterProperties = structure->m_hasGetterSetterProperties; 449 450 // Don't set m_offset, as one can not transition to this. 451 452 structure->materializePropertyMapIfNecessary(); 453 transition->m_propertyTable = structure->copyPropertyTable(); 454 transition->m_isPinnedPropertyTable = true; 455 456 bool removed = transition->despecifyFunction(replaceFunction); 457 ASSERT_UNUSED(removed, removed); 433 458 434 459 return transition.release(); … … 482 507 } 483 508 484 size_t Structure::addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes )509 size_t Structure::addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes, JSCell* specificValue) 485 510 { 486 511 ASSERT(!m_transitions.singleTransition); … … 489 514 490 515 m_isPinnedPropertyTable = true; 491 size_t offset = put(propertyName, attributes );516 size_t offset = put(propertyName, attributes, specificValue); 492 517 if (propertyStorageSize() > propertyStorageCapacity()) 493 518 growPropertyStorageCapacity(); … … 565 590 } 566 591 567 size_t Structure::get(const Identifier& propertyName, unsigned& attributes) 568 { 569 ASSERT(!propertyName.isNull()); 570 592 size_t Structure::get(const UString::Rep* rep, unsigned& attributes, JSCell*& specificValue) 593 { 571 594 materializePropertyMapIfNecessary(); 572 595 if (!m_propertyTable) 573 596 return notFound; 574 597 575 UString::Rep* rep = propertyName._ustring.rep();576 577 598 unsigned i = rep->computedHash(); 578 599 … … 587 608 if (rep == m_propertyTable->entries()[entryIndex - 1].key) { 588 609 attributes = m_propertyTable->entries()[entryIndex - 1].attributes; 610 specificValue = m_propertyTable->entries()[entryIndex - 1].specificValue; 589 611 return m_propertyTable->entries()[entryIndex - 1].offset; 590 612 } … … 609 631 if (rep == m_propertyTable->entries()[entryIndex - 1].key) { 610 632 attributes = m_propertyTable->entries()[entryIndex - 1].attributes; 633 specificValue = m_propertyTable->entries()[entryIndex - 1].specificValue; 611 634 return m_propertyTable->entries()[entryIndex - 1].offset; 612 635 } … … 614 637 } 615 638 616 size_t Structure::put(const Identifier& propertyName, unsigned attributes) 639 bool Structure::despecifyFunction(const Identifier& propertyName) 640 { 641 ASSERT(!propertyName.isNull()); 642 643 materializePropertyMapIfNecessary(); 644 if (!m_propertyTable) 645 return false; 646 647 UString::Rep* rep = propertyName._ustring.rep(); 648 649 unsigned i = rep->computedHash(); 650 651 #if DUMP_PROPERTYMAP_STATS 652 ++numProbes; 653 #endif 654 655 unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask]; 656 if (entryIndex == emptyEntryIndex) 657 return false; 658 659 if (rep == m_propertyTable->entries()[entryIndex - 1].key) { 660 ASSERT(m_propertyTable->entries()[entryIndex - 1].specificValue); 661 m_propertyTable->entries()[entryIndex - 1].specificValue = 0; 662 return true; 663 } 664 665 #if DUMP_PROPERTYMAP_STATS 666 ++numCollisions; 667 #endif 668 669 unsigned k = 1 | doubleHash(rep->computedHash()); 670 671 while (1) { 672 i += k; 673 674 #if DUMP_PROPERTYMAP_STATS 675 ++numRehashes; 676 #endif 677 678 entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask]; 679 if (entryIndex == emptyEntryIndex) 680 return false; 681 682 if (rep == m_propertyTable->entries()[entryIndex - 1].key) { 683 ASSERT(m_propertyTable->entries()[entryIndex - 1].specificValue); 684 m_propertyTable->entries()[entryIndex - 1].specificValue = 0; 685 return true; 686 } 687 } 688 } 689 690 size_t Structure::put(const Identifier& propertyName, unsigned attributes, JSCell* specificValue) 617 691 { 618 692 ASSERT(!propertyName.isNull()); … … 684 758 m_propertyTable->entries()[entryIndex - 1].key = rep; 685 759 m_propertyTable->entries()[entryIndex - 1].attributes = attributes; 760 m_propertyTable->entries()[entryIndex - 1].specificValue = specificValue; 686 761 m_propertyTable->entries()[entryIndex - 1].index = ++m_propertyTable->lastIndexUsed; 687 762 … … 756 831 m_propertyTable->entries()[entryIndex - 1].key = 0; 757 832 m_propertyTable->entries()[entryIndex - 1].attributes = 0; 833 m_propertyTable->entries()[entryIndex - 1].specificValue = 0; 758 834 m_propertyTable->entries()[entryIndex - 1].offset = 0; 759 835
Note:
See TracChangeset
for help on using the changeset viewer.