Changeset 12523 in webkit for trunk/JavaScriptCore
- Timestamp:
- Feb 2, 2006, 12:22:43 AM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r12512 r12523 1 2006-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 1 28 2006-01-31 Maciej Stachowiak <[email protected]> 2 29 -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r12435 r12523 53 53 65EA4C9B092AF9E20093D800 /* JSLock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65EA4C99092AF9E20093D800 /* JSLock.cpp */; }; 54 54 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, ); }; }; 55 58 930754C108B0F68000AB3056 /* pcre_compile.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.c */; }; 56 59 930754D008B0F74600AB3056 /* pcre_tables.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.c */; }; … … 371 374 8442A376074175C2000AE2ED /* softlinking.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = softlinking.c; path = bindings/softlinking.c; sourceTree = "<group>"; tabWidth = 8; }; 372 375 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>"; }; 373 379 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; }; 374 380 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; }; … … 669 675 isa = PBXGroup; 670 676 children = ( 677 9303F5690991190000AD71B8 /* Noncopyable.h */, 678 9303F567099118FA00AD71B8 /* OwnPtr.h */, 679 9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */, 671 680 6592C316098B7DE10003D4F6 /* Vector.h */, 672 681 6592C317098B7DE10003D4F6 /* VectorTraits.h */, … … 865 874 6592C318098B7DE10003D4F6 /* Vector.h in Headers */, 866 875 6592C319098B7DE10003D4F6 /* VectorTraits.h in Headers */, 876 9303F568099118FA00AD71B8 /* OwnPtr.h in Headers */, 877 9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */, 878 9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */, 867 879 ); 868 880 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/kjs/function.cpp
r12317 r12523 51 51 class Parameter { 52 52 public: 53 Parameter(const Identifier &n) : name(n), next(0L) { } 54 ~Parameter() { delete next; } 53 Parameter(const Identifier &n) : name(n) { } 55 54 Identifier name; 56 Parameter *next;55 OwnPtr<Parameter> next; 57 56 }; 58 57 … … 66 65 FunctionImp::~FunctionImp() 67 66 { 68 delete param;69 67 } 70 68 … … 146 144 void FunctionImp::addParameter(const Identifier &n) 147 145 { 148 Parameter **p = ¶m;146 OwnPtr<Parameter> *p = ¶m; 149 147 while (*p) 150 148 p = &(*p)->next; 151 149 152 *p = new Parameter(n);150 p->set(new Parameter(n)); 153 151 } 154 152 … … 156 154 { 157 155 UString s; 158 const Parameter *p = param ;156 const Parameter *p = param.get(); 159 157 while (p) { 160 158 if (!s.isEmpty()) 161 159 s += ", "; 162 160 s += p->name.ustring(); 163 p = p->next ;161 p = p->next.get(); 164 162 } 165 163 … … 181 179 if (param) { 182 180 ListIterator it = args.begin(); 183 Parameter *p = param ;181 Parameter *p = param.get(); 184 182 JSValue *v = *it; 185 183 while (p) { … … 193 191 } else 194 192 variable->put(exec, p->name, jsUndefined()); 195 p = p->next ;193 p = p->next.get(); 196 194 } 197 195 } … … 224 222 { 225 223 FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase()); 226 const Parameter *p = thisObj->param ;224 const Parameter *p = thisObj->param.get(); 227 225 int count = 0; 228 226 while (p) { 229 227 ++count; 230 p = p->next ;228 p = p->next.get(); 231 229 } 232 230 return jsNumber(count); … … 274 272 { 275 273 int i = 0; 276 Parameter *p = param ;274 Parameter *p = param.get(); 277 275 278 276 if(!p) … … 280 278 281 279 // skip to the parameter we want 282 while (i++ < index && (p = p->next ))280 while (i++ < index && (p = p->next.get())) 283 281 ; 284 282 … … 289 287 290 288 // Are there any subsequent parameters with the same name? 291 while ((p = p->next ))289 while ((p = p->next.get())) 292 290 if (p->name == name) 293 291 return Identifier::null(); -
trunk/JavaScriptCore/kjs/function.h
r12317 r12523 3 3 * This file is part of the KDE libraries 4 4 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 * Copyright (C) 2003 Apple Computer, Inc.5 * Copyright (C) 2003, 2006 Apple Computer, Inc. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 22 22 */ 23 23 24 #ifndef _KJS_FUNCTION_H_25 #define _KJS_FUNCTION_H_24 #ifndef KJS_FUNCTION_H 25 #define KJS_FUNCTION_H 26 26 27 #include "array_instance.h" 27 28 #include "internal.h" 28 #include "array_instance.h"29 #include <kxmlcore/OwnPtr.h> 29 30 30 31 namespace KJS { … … 61 62 static const ClassInfo info; 62 63 protected: 63 Parameter *param;64 OwnPtr<Parameter> param; 64 65 Identifier ident; 65 66 -
trunk/JavaScriptCore/kjs/internal.h
r12317 r12523 32 32 #include "interpreter.h" 33 33 #include "scope_chain.h" 34 #include <kxmlcore/Noncopyable.h> 34 35 #include <kxmlcore/RefPtr.h> 35 36 … … 132 133 * @short The "label set" in Ecma-262 spec 133 134 */ 134 class LabelStack {135 public: 136 LabelStack(): tos(0 L), iterationDepth(0), switchDepth(0) {}135 class LabelStack : Noncopyable { 136 public: 137 LabelStack(): tos(0), iterationDepth(0), switchDepth(0) {} 137 138 ~LabelStack(); 138 139 … … 160 161 161 162 private: 162 LabelStack(const LabelStack &other);163 LabelStack &operator=(const LabelStack &other);164 165 163 struct StackElem { 166 164 Identifier id; -
trunk/JavaScriptCore/kjs/list.cpp
r12317 r12523 25 25 #include "internal.h" 26 26 #include <algorithm> 27 #include <kxmlcore/OwnArrayPtr.h> 27 28 28 29 #define DUMP_STATISTICS 0 … … 42 43 ListImpState state; 43 44 int capacity; 44 JSValue **overflow;45 OwnArrayPtr<JSValue*> overflow; 45 46 46 47 union { … … 171 172 imp->valueRefCount = 1; 172 173 imp->capacity = 0; 173 imp->overflow = 0;174 174 #if DUMP_STATISTICS 175 175 if (++numLists > numListsHighWaterMark) … … 186 186 imp->valueRefCount = !needsMarking; 187 187 imp->capacity = 0; 188 imp->overflow = 0;189 188 190 189 #if DUMP_STATISTICS … … 212 211 #endif 213 212 214 delete [] imp->overflow;213 imp->overflow.clear(); 215 214 216 215 if (imp->state == usedInPool) { … … 273 272 if (i >= imp->capacity) { 274 273 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(); 277 276 int oldOverflowSize = i - inlineValuesSize; 278 277 for (int j = 0; j != oldOverflowSize; j++) 279 278 newOverflow[j] = oldOverflow[j]; 280 delete [] oldOverflow; 281 imp->overflow = newOverflow; 279 imp->overflow.swap(newOverflow); 282 280 imp->capacity = newCapacity; 283 281 } … … 303 301 append(imp->values[i]); 304 302 305 JSValue **overflow = imp->overflow;303 JSValue** overflow = imp->overflow.get(); 306 304 int overflowSize = size - inlineSize; 307 305 for (int i = 0; i != overflowSize; ++i) … … 322 320 copy.append(imp->values[i]); 323 321 324 JSValue **overflow = imp->overflow;322 JSValue** overflow = imp->overflow.get(); 325 323 int overflowSize = size - inlineSize; 326 324 for (int i = 0; i < overflowSize; ++i) -
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 } -
trunk/JavaScriptCore/kjs/property_map.h
r12317 r12523 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 2004 Apple Computer, Inc.4 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 21 21 */ 22 22 23 #ifndef _KJS_PROPERTY_MAP_H_24 #define _KJS_PROPERTY_MAP_H_23 #ifndef KJS_PROPERTY_MAP_H_ 24 #define KJS_PROPERTY_MAP_H_ 25 25 26 26 #include "identifier.h" 27 #include <kxmlcore/OwnArrayPtr.h> 27 28 28 29 namespace KJS { … … 47 48 private: 48 49 int _count; 49 SavedProperty *_properties; 50 51 SavedProperties(const SavedProperties&); 52 SavedProperties& operator=(const SavedProperties&); 50 OwnArrayPtr<SavedProperty> _properties; 53 51 }; 54 52 … … 65 63 int index; 66 64 }; 65 67 66 /** 68 67 * Javascript Property Map. 69 68 */ 70 71 69 class PropertyMap { 72 70 public: -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r12317 r12523 195 195 RegExpPrototype *regProto) 196 196 197 : InternalFunctionImp(funcProto), multiline(false), lastInput(""), last Ovector(0), lastNumSubPatterns(0)197 : InternalFunctionImp(funcProto), multiline(false), lastInput(""), lastNumSubPatterns(0) 198 198 { 199 199 // ECMA 15.10.5.1 RegExp.prototype … … 202 202 // no. of arguments for constructor 203 203 putDirect(lengthPropertyName, jsNumber(2), ReadOnly|DontDelete|DontEnum); 204 }205 206 RegExpObjectImp::~RegExpObjectImp()207 {208 delete [] lastOvector;209 204 } 210 205 … … 226 221 227 222 if (!match.isNull()) { 228 assert(tmpOvector);223 ASSERT(tmpOvector); 229 224 230 225 lastInput = s; 231 delete [] lastOvector; 232 lastOvector = tmpOvector; 226 lastOvector.set(tmpOvector); 233 227 lastNumSubPatterns = r->subPatterns(); 234 228 } … … 283 277 int i = lastNumSubPatterns; 284 278 if (i > 0) { 285 assert(lastOvector);279 ASSERT(lastOvector); 286 280 UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i]); 287 281 return jsString(substring); … … 351 345 return getRightContext(); 352 346 default: 353 assert(0);347 ASSERT(0); 354 348 } 355 349 … … 372 366 break; 373 367 default: 374 assert(0);368 ASSERT(0); 375 369 } 376 370 } -
trunk/JavaScriptCore/kjs/regexp_object.h
r12317 r12523 26 26 #include "function_object.h" 27 27 #include "regexp.h" 28 #include <kxmlcore/OwnArrayPtr.h> 28 29 29 30 namespace KJS { … … 72 73 FunctionPrototype *funcProto, 73 74 RegExpPrototype *regProto); 74 virtual ~RegExpObjectImp();75 75 virtual bool implementsConstruct() const; 76 76 virtual JSObject *construct(ExecState *exec, const List &args); … … 96 96 bool multiline; 97 97 UString lastInput; 98 int *lastOvector;98 OwnArrayPtr<int> lastOvector; 99 99 unsigned lastNumSubPatterns; 100 100
Note:
See TracChangeset
for help on using the changeset viewer.