Changeset 29943 in webkit for trunk/JavaScriptCore/kjs/property_map.cpp
- Timestamp:
- Feb 2, 2008, 4:20:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/property_map.cpp
r28884 r29943 1 1 /* 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 127 127 128 128 SavedProperties::SavedProperties() 129 : m_count(0)129 : count(0) 130 130 { 131 131 } … … 717 717 } 718 718 719 void PropertyMap::save(SavedProperties &p) const719 void PropertyMap::save(SavedProperties& s) const 720 720 { 721 721 unsigned count = 0; … … 733 733 } 734 734 735 p.m_properties.clear();736 p.m_count = count;735 s.properties.clear(); 736 s.count = count; 737 737 738 738 if (count == 0) 739 739 return; 740 740 741 p.m_properties.set(new SavedProperty [count]); 742 743 SavedProperty* prop = p.m_properties.get(); 744 745 if (!m_usingTable) { 746 #if USE_SINGLE_ENTRY 747 if (m_singleEntryKey && !(m_singleEntryAttributes & (ReadOnly | Function))) { 748 prop->key = Identifier(m_singleEntryKey); 749 prop->value = m_u.singleEntryValue; 750 prop->attributes = m_singleEntryAttributes; 751 ++prop; 752 } 753 #endif 754 } else { 755 // Save in the right order so we don't lose the order. 756 // Another possibility would be to save the indices. 757 758 // Allocate a buffer to use to sort the keys. 759 Vector<Entry*, smallMapThreshold> sortedEntries(count); 760 761 // Get pointers to the entries in the buffer. 762 Entry** p = sortedEntries.data(); 763 unsigned entryCount = m_u.table->keyCount + m_u.table->deletedSentinelCount; 764 for (unsigned i = 1; i <= entryCount; ++i) { 765 if (m_u.table->entries()[i].key && !(m_u.table->entries()[i].attributes & (ReadOnly | Function))) 766 *p++ = &m_u.table->entries()[i]; 767 } 768 ASSERT(p == sortedEntries.data() + count); 769 770 // Sort the entries by index. 771 qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 772 773 // Put the sorted entries into the saved properties list. 774 for (Entry** q = sortedEntries.data(); q != p; ++q, ++prop) { 775 Entry* e = *q; 776 prop->key = Identifier(e->key); 777 prop->value = e->value; 778 prop->attributes = e->attributes; 779 } 780 } 781 } 782 783 void PropertyMap::restore(const SavedProperties &p) 784 { 785 for (unsigned i = 0; i != p.m_count; ++i) 786 put(p.m_properties[i].key, p.m_properties[i].value, p.m_properties[i].attributes); 741 s.properties.set(new SavedProperty[count]); 742 743 SavedProperty* prop = s.properties.get(); 744 745 #if USE_SINGLE_ENTRY 746 if (!m_usingTable) { 747 prop->init(m_singleEntryKey, m_u.singleEntryValue, m_singleEntryAttributes); 748 return; 749 } 750 #endif 751 752 // Save in the right order so we don't lose the order. 753 // Another possibility would be to save the indices. 754 755 // Allocate a buffer to use to sort the keys. 756 Vector<Entry*, smallMapThreshold> sortedEntries(count); 757 758 // Get pointers to the entries in the buffer. 759 Entry** p = sortedEntries.data(); 760 unsigned entryCount = m_u.table->keyCount + m_u.table->deletedSentinelCount; 761 for (unsigned i = 1; i <= entryCount; ++i) { 762 if (m_u.table->entries()[i].key && !(m_u.table->entries()[i].attributes & (ReadOnly | Function))) 763 *p++ = &m_u.table->entries()[i]; 764 } 765 ASSERT(p == sortedEntries.data() + count); 766 767 // Sort the entries by index. 768 qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 769 770 // Put the sorted entries into the saved properties list. 771 for (Entry** q = sortedEntries.data(); q != p; ++q, ++prop) { 772 Entry* e = *q; 773 prop->init(e->key, e->value, e->attributes); 774 } 775 } 776 777 void PropertyMap::restore(const SavedProperties& p) 778 { 779 for (unsigned i = 0; i != p.count; ++i) 780 put(Identifier(p.properties[i].name()), p.properties[i].value(), p.properties[i].attributes()); 787 781 } 788 782
Note:
See TracChangeset
for help on using the changeset viewer.