Changeset 12523 in webkit for trunk/JavaScriptCore/kjs/property_map.cpp
- Timestamp:
- Feb 2, 2006, 12:22:43 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/property_map.cpp
r12317 r12523 1 1 /* 2 2 * This file is part of the KDE libraries 3 * Copyright (C) 2004 Apple Computer, Inc.3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 23 23 #include "property_map.h" 24 24 25 #include <kxmlcore/FastMalloc.h>26 25 #include "object.h" 27 26 #include "protect.h" 28 27 #include "reference_list.h" 29 30 28 #include <algorithm> 29 #include <kxmlcore/FastMalloc.h> 30 #include <kxmlcore/Vector.h> 31 31 32 32 using std::max; … … 95 95 }; 96 96 97 SavedProperties::SavedProperties() : _count(0), _properties(0) { } 98 99 SavedProperties::~SavedProperties() 100 { 101 delete [] _properties; 102 } 97 SavedProperties::SavedProperties() : _count(0) { } 98 SavedProperties::~SavedProperties() { } 103 99 104 100 // Algorithm concepts from Algorithms in C++, Sedgewick. … … 598 594 599 595 // Allocate a buffer to use to sort the keys. 600 Entry *fixedSizeBuffer[smallMapThreshold]; 601 Entry **sortedEnumerables; 602 if (_table->keyCount <= smallMapThreshold) 603 sortedEnumerables = fixedSizeBuffer; 604 else 605 sortedEnumerables = new Entry *[_table->keyCount]; 596 Vector<Entry*, smallMapThreshold> sortedEnumerables(_table->keyCount); 606 597 607 598 // Get pointers to the enumerable entries in the buffer. 608 Entry **p = sortedEnumerables;599 Entry** p = sortedEnumerables.data(); 609 600 int size = _table->size; 610 Entry *entries = _table->entries;601 Entry* entries = _table->entries; 611 602 for (int i = 0; i != size; ++i) { 612 Entry *e = &entries[i];603 Entry* e = &entries[i]; 613 604 if (e->key && !(e->attributes & DontEnum)) 614 605 *p++ = e; … … 616 607 617 608 // Sort the entries by index. 618 qsort(sortedEnumerables , p - sortedEnumerables, sizeof(sortedEnumerables[0]), comparePropertyMapEntryIndices);609 qsort(sortedEnumerables.data(), p - sortedEnumerables.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 619 610 620 611 // Put the keys of the sorted entries into the reference list. 621 Entry **q = sortedEnumerables; 622 while (q != p) 623 list.append(Reference(base, Identifier((*q++)->key))); 624 625 // Deallocate the buffer. 626 if (sortedEnumerables != fixedSizeBuffer) 627 delete [] sortedEnumerables; 612 for (Entry** q = sortedEnumerables.data(); q != p; ++q) 613 list.append(Reference(base, Identifier((*q)->key))); 628 614 } 629 615 … … 675 661 } 676 662 677 delete [] p._properties; 678 663 p._properties.clear(); 679 664 p._count = count; 680 665 681 if (count == 0) { 682 p._properties = 0; 683 return; 684 } 685 686 p._properties = new SavedProperty [count]; 687 688 SavedProperty *prop = p._properties; 666 if (count == 0) 667 return; 668 669 p._properties.set(new SavedProperty [count]); 670 671 SavedProperty *prop = p._properties.get(); 689 672 690 673 if (!_table) { … … 702 685 703 686 // Allocate a buffer to use to sort the keys. 704 Entry *fixedSizeBuffer[smallMapThreshold]; 705 Entry **sortedEntries; 706 if (count <= smallMapThreshold) 707 sortedEntries = fixedSizeBuffer; 708 else 709 sortedEntries = new Entry *[count]; 687 Vector<Entry*, smallMapThreshold> sortedEntries(count); 710 688 711 689 // Get pointers to the entries in the buffer. 712 Entry **p = sortedEntries;690 Entry** p = sortedEntries.data(); 713 691 int size = _table->size; 714 Entry *entries = _table->entries;692 Entry* entries = _table->entries; 715 693 for (int i = 0; i != size; ++i) { 716 694 Entry *e = &entries[i]; … … 718 696 *p++ = e; 719 697 } 720 assert(p - sortedEntries == count);698 assert(p - sortedEntries.data() == count); 721 699 722 700 // Sort the entries by index. 723 qsort(sortedEntries , p - sortedEntries, sizeof(sortedEntries[0]), comparePropertyMapEntryIndices);701 qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 724 702 725 703 // Put the sorted entries into the saved properties list. 726 Entry **q = sortedEntries; 727 while (q != p) { 728 Entry *e = *q++; 704 for (Entry** q = sortedEntries.data(); q != p; ++q, ++prop) { 705 Entry* e = *q; 729 706 prop->key = Identifier(e->key); 730 707 prop->value = e->value; 731 708 prop->attributes = e->attributes; 732 ++prop; 733 } 734 735 // Deallocate the buffer. 736 if (sortedEntries != fixedSizeBuffer) 737 delete [] sortedEntries; 709 } 738 710 } 739 711 }
Note:
See TracChangeset
for help on using the changeset viewer.