Ignore:
Timestamp:
Feb 2, 2006, 12:22:43 AM (19 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • kxmlcore/Noncopyable.h: Added.
  • kxmlcore/OwnArrayPtr.h: Added.
  • kxmlcore/OwnPtr.h: Added.
  • kjs/function.h:
  • kjs/function.cpp: Use OwnPtr for Parameter pointers.
  • kjs/internal.h: Use Noncopyable for LabelStack.
  • kjs/list.cpp: Use OwnArrayPtr for overflow.
  • kjs/property_map.h:
  • kjs/property_map.cpp: Use OwnArrayPtr for SavedProperties. Use Vector for some stack buffers.
  • kjs/regexp_object.h:
  • kjs/regexp_object.cpp: Use OwnArrayPtr for lastOvector.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r12317 r12523  
    11/*
    22 *  This file is part of the KDE libraries
    3  *  Copyright (C) 2004 Apple Computer, Inc.
     3 *  Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    2323#include "property_map.h"
    2424
    25 #include <kxmlcore/FastMalloc.h>
    2625#include "object.h"
    2726#include "protect.h"
    2827#include "reference_list.h"
    29 
    3028#include <algorithm>
     29#include <kxmlcore/FastMalloc.h>
     30#include <kxmlcore/Vector.h>
    3131
    3232using std::max;
     
    9595};
    9696
    97 SavedProperties::SavedProperties() : _count(0), _properties(0) { }
    98 
    99 SavedProperties::~SavedProperties()
    100 {
    101     delete [] _properties;
    102 }
     97SavedProperties::SavedProperties() : _count(0) { }
     98SavedProperties::~SavedProperties() { }
    10399
    104100// Algorithm concepts from Algorithms in C++, Sedgewick.
     
    598594
    599595    // 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);
    606597
    607598    // Get pointers to the enumerable entries in the buffer.
    608     Entry **p = sortedEnumerables;
     599    Entry** p = sortedEnumerables.data();
    609600    int size = _table->size;
    610     Entry *entries = _table->entries;
     601    Entry* entries = _table->entries;
    611602    for (int i = 0; i != size; ++i) {
    612         Entry *e = &entries[i];
     603        Entry* e = &entries[i];
    613604        if (e->key && !(e->attributes & DontEnum))
    614605            *p++ = e;
     
    616607
    617608    // Sort the entries by index.
    618     qsort(sortedEnumerables, p - sortedEnumerables, sizeof(sortedEnumerables[0]), comparePropertyMapEntryIndices);
     609    qsort(sortedEnumerables.data(), p - sortedEnumerables.data(), sizeof(Entry*), comparePropertyMapEntryIndices);
    619610
    620611    // 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)));
    628614}
    629615
     
    675661    }
    676662
    677     delete [] p._properties;
    678 
     663    p._properties.clear();
    679664    p._count = count;
    680665
    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();
    689672   
    690673    if (!_table) {
     
    702685
    703686        // 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);
    710688
    711689        // Get pointers to the entries in the buffer.
    712         Entry **p = sortedEntries;
     690        Entry** p = sortedEntries.data();
    713691        int size = _table->size;
    714         Entry *entries = _table->entries;
     692        Entry* entries = _table->entries;
    715693        for (int i = 0; i != size; ++i) {
    716694            Entry *e = &entries[i];
     
    718696                *p++ = e;
    719697        }
    720         assert(p - sortedEntries == count);
     698        assert(p - sortedEntries.data() == count);
    721699
    722700        // Sort the entries by index.
    723         qsort(sortedEntries, p - sortedEntries, sizeof(sortedEntries[0]), comparePropertyMapEntryIndices);
     701        qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices);
    724702
    725703        // 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;
    729706            prop->key = Identifier(e->key);
    730707            prop->value = e->value;
    731708            prop->attributes = e->attributes;
    732             ++prop;
    733         }
    734 
    735         // Deallocate the buffer.
    736         if (sortedEntries != fixedSizeBuffer)
    737             delete [] sortedEntries;
     709        }
    738710    }
    739711}
Note: See TracChangeset for help on using the changeset viewer.