Changeset 12523 in webkit for trunk/JavaScriptCore


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.
Location:
trunk/JavaScriptCore
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r12512 r12523  
     12006-02-02  Darin Adler  <[email protected]>
     2
     3        Reviewed by Maciej.
     4
     5        - http://bugzilla.opendarwin.org/show_bug.cgi?id=7005
     6          add Noncopyable, OwnPtr, OwnArrayPtr to KXMLCore
     7
     8        * kxmlcore/Noncopyable.h: Added.
     9        * kxmlcore/OwnArrayPtr.h: Added.
     10        * kxmlcore/OwnPtr.h: Added.
     11
     12        * JavaScriptCore.xcodeproj/project.pbxproj: Added new files.
     13
     14        * kjs/function.h:
     15        * kjs/function.cpp: Use OwnPtr for Parameter pointers.
     16
     17        * kjs/internal.h: Use Noncopyable for LabelStack.
     18
     19        * kjs/list.cpp: Use OwnArrayPtr for overflow.
     20
     21        * kjs/property_map.h:
     22        * kjs/property_map.cpp: Use OwnArrayPtr for SavedProperties.
     23        Use Vector for some stack buffers.
     24
     25        * kjs/regexp_object.h:
     26        * kjs/regexp_object.cpp: Use OwnArrayPtr for lastOvector.
     27
    1282006-01-31  Maciej Stachowiak  <[email protected]>
    229
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r12435 r12523  
    5353                65EA4C9B092AF9E20093D800 /* JSLock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65EA4C99092AF9E20093D800 /* JSLock.cpp */; };
    5454                65EA4C9C092AF9E20093D800 /* JSLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 65EA4C9A092AF9E20093D800 /* JSLock.h */; settings = {ATTRIBUTES = (Private, ); }; };
     55                9303F568099118FA00AD71B8 /* OwnPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 9303F567099118FA00AD71B8 /* OwnPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
     56                9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9303F5690991190000AD71B8 /* Noncopyable.h */; settings = {ATTRIBUTES = (Private, ); }; };
     57                9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5558                930754C108B0F68000AB3056 /* pcre_compile.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.c */; };
    5659                930754D008B0F74600AB3056 /* pcre_tables.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.c */; };
     
    371374                8442A376074175C2000AE2ED /* softlinking.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = softlinking.c; path = bindings/softlinking.c; sourceTree = "<group>"; tabWidth = 8; };
    372375                84ABF1DE070B628C00A3AC05 /* npruntime_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = npruntime_impl.h; path = bindings/npruntime_impl.h; sourceTree = "<group>"; tabWidth = 8; };
     376                9303F567099118FA00AD71B8 /* OwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtr.h; sourceTree = "<group>"; };
     377                9303F5690991190000AD71B8 /* Noncopyable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noncopyable.h; sourceTree = "<group>"; };
     378                9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnArrayPtr.h; sourceTree = "<group>"; };
    373379                930754BF08B0F68000AB3056 /* pcre_compile.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_compile.c; path = pcre/pcre_compile.c; sourceTree = "<group>"; tabWidth = 8; };
    374380                930754CE08B0F74500AB3056 /* pcre_tables.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_tables.c; path = pcre/pcre_tables.c; sourceTree = "<group>"; tabWidth = 8; };
     
    669675                        isa = PBXGroup;
    670676                        children = (
     677                                9303F5690991190000AD71B8 /* Noncopyable.h */,
     678                                9303F567099118FA00AD71B8 /* OwnPtr.h */,
     679                                9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
    671680                                6592C316098B7DE10003D4F6 /* Vector.h */,
    672681                                6592C317098B7DE10003D4F6 /* VectorTraits.h */,
     
    865874                                6592C318098B7DE10003D4F6 /* Vector.h in Headers */,
    866875                                6592C319098B7DE10003D4F6 /* VectorTraits.h in Headers */,
     876                                9303F568099118FA00AD71B8 /* OwnPtr.h in Headers */,
     877                                9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */,
     878                                9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */,
    867879                        );
    868880                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/kjs/function.cpp

    r12317 r12523  
    5151  class Parameter {
    5252  public:
    53     Parameter(const Identifier &n) : name(n), next(0L) { }
    54     ~Parameter() { delete next; }
     53    Parameter(const Identifier &n) : name(n) { }
    5554    Identifier name;
    56     Parameter *next;
     55    OwnPtr<Parameter> next;
    5756  };
    5857
     
    6665FunctionImp::~FunctionImp()
    6766{
    68   delete param;
    6967}
    7068
     
    146144void FunctionImp::addParameter(const Identifier &n)
    147145{
    148   Parameter **p = &param;
     146  OwnPtr<Parameter> *p = &param;
    149147  while (*p)
    150148    p = &(*p)->next;
    151149
    152   *p = new Parameter(n);
     150  p->set(new Parameter(n));
    153151}
    154152
     
    156154{
    157155  UString s;
    158   const Parameter *p = param;
     156  const Parameter *p = param.get();
    159157  while (p) {
    160158    if (!s.isEmpty())
    161159        s += ", ";
    162160    s += p->name.ustring();
    163     p = p->next;
     161    p = p->next.get();
    164162  }
    165163
     
    181179  if (param) {
    182180    ListIterator it = args.begin();
    183     Parameter *p = param;
     181    Parameter *p = param.get();
    184182    JSValue  *v = *it;
    185183    while (p) {
     
    193191      } else
    194192        variable->put(exec, p->name, jsUndefined());
    195       p = p->next;
     193      p = p->next.get();
    196194    }
    197195  }
     
    224222{
    225223  FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase());
    226   const Parameter *p = thisObj->param;
     224  const Parameter *p = thisObj->param.get();
    227225  int count = 0;
    228226  while (p) {
    229227    ++count;
    230     p = p->next;
     228    p = p->next.get();
    231229  }
    232230  return jsNumber(count);
     
    274272{
    275273  int i = 0;
    276   Parameter *p = param;
     274  Parameter *p = param.get();
    277275 
    278276  if(!p)
     
    280278 
    281279  // skip to the parameter we want
    282   while (i++ < index && (p = p->next))
     280  while (i++ < index && (p = p->next.get()))
    283281    ;
    284282 
     
    289287
    290288  // Are there any subsequent parameters with the same name?
    291   while ((p = p->next))
     289  while ((p = p->next.get()))
    292290    if (p->name == name)
    293291      return Identifier::null();
  • trunk/JavaScriptCore/kjs/function.h

    r12317 r12523  
    33 *  This file is part of the KDE libraries
    44 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    5  *  Copyright (C) 2003 Apple Computer, Inc.
     5 *  Copyright (C) 2003, 2006 Apple Computer, Inc.
    66 *
    77 *  This library is free software; you can redistribute it and/or
     
    2222 */
    2323
    24 #ifndef _KJS_FUNCTION_H_
    25 #define _KJS_FUNCTION_H_
     24#ifndef KJS_FUNCTION_H
     25#define KJS_FUNCTION_H
    2626
     27#include "array_instance.h"
    2728#include "internal.h"
    28 #include "array_instance.h"
     29#include <kxmlcore/OwnPtr.h>
    2930
    3031namespace KJS {
     
    6162    static const ClassInfo info;
    6263  protected:
    63     Parameter *param;
     64    OwnPtr<Parameter> param;
    6465    Identifier ident;
    6566
  • trunk/JavaScriptCore/kjs/internal.h

    r12317 r12523  
    3232#include "interpreter.h"
    3333#include "scope_chain.h"
     34#include <kxmlcore/Noncopyable.h>
    3435#include <kxmlcore/RefPtr.h>
    3536
     
    132133   * @short The "label set" in Ecma-262 spec
    133134   */
    134   class LabelStack {
    135   public:
    136     LabelStack(): tos(0L), iterationDepth(0), switchDepth(0) {}
     135  class LabelStack : Noncopyable {
     136  public:
     137    LabelStack(): tos(0), iterationDepth(0), switchDepth(0) {}
    137138    ~LabelStack();
    138139
     
    160161   
    161162  private:
    162     LabelStack(const LabelStack &other);
    163     LabelStack &operator=(const LabelStack &other);
    164 
    165163    struct StackElem {
    166164      Identifier id;
  • trunk/JavaScriptCore/kjs/list.cpp

    r12317 r12523  
    2525#include "internal.h"
    2626#include <algorithm>
     27#include <kxmlcore/OwnArrayPtr.h>
    2728
    2829#define DUMP_STATISTICS 0
     
    4243    ListImpState state;
    4344    int capacity;
    44     JSValue **overflow;
     45    OwnArrayPtr<JSValue*> overflow;
    4546
    4647    union {
     
    171172    imp->valueRefCount = 1;
    172173    imp->capacity = 0;
    173     imp->overflow = 0;
    174174#if DUMP_STATISTICS
    175175    if (++numLists > numListsHighWaterMark)
     
    186186    imp->valueRefCount = !needsMarking;
    187187    imp->capacity = 0;
    188     imp->overflow = 0;
    189188
    190189#if DUMP_STATISTICS
     
    212211#endif
    213212
    214     delete [] imp->overflow;
     213    imp->overflow.clear();
    215214
    216215    if (imp->state == usedInPool) {
     
    273272    if (i >= imp->capacity) {
    274273        int newCapacity = i * 2;
    275         JSValue **newOverflow = new JSValue * [newCapacity - inlineValuesSize];
    276         JSValue **oldOverflow = imp->overflow;
     274        OwnArrayPtr<JSValue*> newOverflow(new JSValue* [newCapacity - inlineValuesSize]);
     275        JSValue** oldOverflow = imp->overflow.get();
    277276        int oldOverflowSize = i - inlineValuesSize;
    278277        for (int j = 0; j != oldOverflowSize; j++)
    279278            newOverflow[j] = oldOverflow[j];
    280         delete [] oldOverflow;
    281         imp->overflow = newOverflow;
     279        imp->overflow.swap(newOverflow);
    282280        imp->capacity = newCapacity;
    283281    }
     
    303301        append(imp->values[i]);
    304302
    305     JSValue **overflow = imp->overflow;
     303    JSValue** overflow = imp->overflow.get();
    306304    int overflowSize = size - inlineSize;
    307305    for (int i = 0; i != overflowSize; ++i)
     
    322320        copy.append(imp->values[i]);
    323321
    324     JSValue **overflow = imp->overflow;
     322    JSValue** overflow = imp->overflow.get();
    325323    int overflowSize = size - inlineSize;
    326324    for (int i = 0; i < overflowSize; ++i)
  • 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}
  • trunk/JavaScriptCore/kjs/property_map.h

    r12317 r12523  
    22/*
    33 *  This file is part of the KDE libraries
    4  *  Copyright (C) 2004 Apple Computer, Inc.
     4 *  Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2121 */
    2222
    23 #ifndef _KJS_PROPERTY_MAP_H_
    24 #define _KJS_PROPERTY_MAP_H_
     23#ifndef KJS_PROPERTY_MAP_H_
     24#define KJS_PROPERTY_MAP_H_
    2525
    2626#include "identifier.h"
     27#include <kxmlcore/OwnArrayPtr.h>
    2728
    2829namespace KJS {
     
    4748    private:
    4849        int _count;
    49         SavedProperty *_properties;
    50        
    51         SavedProperties(const SavedProperties&);
    52         SavedProperties& operator=(const SavedProperties&);
     50        OwnArrayPtr<SavedProperty> _properties;
    5351    };
    5452   
     
    6563        int index;
    6664    };
     65
    6766/**
    6867* Javascript Property Map.
    6968*/
    70 
    7169    class PropertyMap {
    7270    public:
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r12317 r12523  
    195195                                 RegExpPrototype *regProto)
    196196
    197   : InternalFunctionImp(funcProto), multiline(false), lastInput(""), lastOvector(0), lastNumSubPatterns(0)
     197  : InternalFunctionImp(funcProto), multiline(false), lastInput(""), lastNumSubPatterns(0)
    198198{
    199199  // ECMA 15.10.5.1 RegExp.prototype
     
    202202  // no. of arguments for constructor
    203203  putDirect(lengthPropertyName, jsNumber(2), ReadOnly|DontDelete|DontEnum);
    204 }
    205 
    206 RegExpObjectImp::~RegExpObjectImp()
    207 {
    208   delete [] lastOvector;
    209204}
    210205
     
    226221 
    227222  if (!match.isNull()) {
    228     assert(tmpOvector);
     223    ASSERT(tmpOvector);
    229224   
    230225    lastInput = s;
    231     delete [] lastOvector;
    232     lastOvector = tmpOvector;
     226    lastOvector.set(tmpOvector);
    233227    lastNumSubPatterns = r->subPatterns();
    234228  }
     
    283277  int i = lastNumSubPatterns;
    284278  if (i > 0) {
    285     assert(lastOvector);
     279    ASSERT(lastOvector);
    286280    UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i]);
    287281    return jsString(substring);
     
    351345      return getRightContext();
    352346    default:
    353       assert(0);
     347      ASSERT(0);
    354348  }
    355349
     
    372366      break;
    373367    default:
    374       assert(0);
     368      ASSERT(0);
    375369  }
    376370}
  • trunk/JavaScriptCore/kjs/regexp_object.h

    r12317 r12523  
    2626#include "function_object.h"
    2727#include "regexp.h"
     28#include <kxmlcore/OwnArrayPtr.h>
    2829
    2930namespace KJS {
     
    7273                    FunctionPrototype *funcProto,
    7374                    RegExpPrototype *regProto);
    74     virtual ~RegExpObjectImp();
    7575    virtual bool implementsConstruct() const;
    7676    virtual JSObject *construct(ExecState *exec, const List &args);
     
    9696    bool multiline;
    9797    UString lastInput;
    98     int *lastOvector;
     98    OwnArrayPtr<int> lastOvector;
    9999    unsigned lastNumSubPatterns;
    100100   
Note: See TracChangeset for help on using the changeset viewer.