source: webkit/trunk/JavaScriptCore/kjs/identifier.h@ 38061

Last change on this file since 38061 was 38016, checked in by [email protected], 17 years ago

2008-10-30 Sam Weinig <[email protected]>

Reviewed by Cameron Zwarich and Geoffrey Garen.

Fix for https://bugs.webkit.org/show_bug.cgi?id=21989
Merge PropertyMap and StructureID

  • Move PropertyMap code into StructureID in preparation for lazily creating the map on gets.
  • Make remove with transition explicit by adding removePropertyTransition.
  • Make the put/remove without transition explicit.
  • Make cache invalidation part of put/remove without transition.

1% speedup on SunSpider; 0.5% speedup on v8 suite.

  • GNUmakefile.am:
  • JavaScriptCore.exp:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • kjs/AllInOneFile.cpp:
  • kjs/identifier.h:
  • runtime/JSObject.cpp: (JSC::JSObject::removeDirect):
  • runtime/JSObject.h: (JSC::JSObject::putDirect):
  • runtime/PropertyMap.cpp: Removed.
  • runtime/PropertyMap.h: Removed.
  • runtime/PropertyMapHashTable.h: Copied from runtime/PropertyMap.h.
  • runtime/StructureID.cpp: (JSC::StructureID::dumpStatistics): (JSC::StructureID::StructureID): (JSC::StructureID::~StructureID): (JSC::StructureID::getEnumerablePropertyNames): (JSC::StructureID::addPropertyTransition): (JSC::StructureID::removePropertyTransition): (JSC::StructureID::toDictionaryTransition): (JSC::StructureID::changePrototypeTransition): (JSC::StructureID::getterSetterTransition): (JSC::StructureID::addPropertyWithoutTransition): (JSC::StructureID::removePropertyWithoutTransition): (JSC::PropertyMapStatisticsExitLogger::~PropertyMapStatisticsExitLogger): (JSC::StructureID::checkConsistency): (JSC::StructureID::copyPropertyTable): (JSC::StructureID::get): (JSC::StructureID::put): (JSC::StructureID::remove): (JSC::StructureID::insertIntoPropertyMapHashTable): (JSC::StructureID::expandPropertyMapHashTable): (JSC::StructureID::createPropertyMapHashTable): (JSC::StructureID::rehashPropertyMapHashTable): (JSC::comparePropertyMapEntryIndices): (JSC::StructureID::getEnumerablePropertyNamesInternal):
  • runtime/StructureID.h: (JSC::StructureID::propertyStorageSize): (JSC::StructureID::isEmpty): (JSC::StructureID::get):
  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef KJS_IDENTIFIER_H
22#define KJS_IDENTIFIER_H
23
24#include "JSGlobalData.h"
25#include "ustring.h"
26
27namespace JSC {
28
29 class ExecState;
30
31 class Identifier {
32 friend class StructureID;
33 public:
34 Identifier() { }
35
36 Identifier(ExecState* exec, const char* s) : _ustring(add(exec, s)) { } // Only to be used with string literals.
37 Identifier(ExecState* exec, const UChar* s, int length) : _ustring(add(exec, s, length)) { }
38 Identifier(ExecState* exec, UString::Rep* rep) : _ustring(add(exec, rep)) { }
39 Identifier(ExecState* exec, const UString& s) : _ustring(add(exec, s.rep())) { }
40
41 Identifier(JSGlobalData* globalData, const char* s) : _ustring(add(globalData, s)) { } // Only to be used with string literals.
42 Identifier(JSGlobalData* globalData, const UChar* s, int length) : _ustring(add(globalData, s, length)) { }
43 Identifier(JSGlobalData* globalData, UString::Rep* rep) : _ustring(add(globalData, rep)) { }
44 Identifier(JSGlobalData* globalData, const UString& s) : _ustring(add(globalData, s.rep())) { }
45
46 // Special constructor for cases where we overwrite an object in place.
47 Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { }
48
49 const UString& ustring() const { return _ustring; }
50
51 const UChar* data() const { return _ustring.data(); }
52 int size() const { return _ustring.size(); }
53
54 const char* ascii() const { return _ustring.ascii(); }
55
56 static Identifier from(ExecState* exec, unsigned y) { return Identifier(exec, UString::from(y)); }
57
58 bool isNull() const { return _ustring.isNull(); }
59 bool isEmpty() const { return _ustring.isEmpty(); }
60
61 uint32_t toUInt32(bool* ok) const { return _ustring.toUInt32(ok); }
62 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); };
63 uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); }
64 unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); }
65 double toDouble() const { return _ustring.toDouble(); }
66
67 friend bool operator==(const Identifier&, const Identifier&);
68 friend bool operator!=(const Identifier&, const Identifier&);
69
70 friend bool operator==(const Identifier&, const char*);
71
72 static void remove(UString::Rep*);
73
74 static bool equal(const UString::Rep*, const char*);
75 static bool equal(const UString::Rep*, const UChar*, int length);
76 static bool equal(const UString::Rep* a, const UString::Rep* b) { return JSC::equal(a, b); }
77
78 static PassRefPtr<UString::Rep> add(ExecState*, const char*); // Only to be used with string literals.
79 static PassRefPtr<UString::Rep> add(JSGlobalData*, const char*); // Only to be used with string literals.
80
81 static void initializeIdentifierThreading();
82
83 private:
84 UString _ustring;
85
86 static bool equal(const Identifier& a, const Identifier& b) { return a._ustring.rep() == b._ustring.rep(); }
87 static bool equal(const Identifier& a, const char* b) { return equal(a._ustring.rep(), b); }
88
89 static PassRefPtr<UString::Rep> add(ExecState*, const UChar*, int length);
90 static PassRefPtr<UString::Rep> add(JSGlobalData*, const UChar*, int length);
91
92 static PassRefPtr<UString::Rep> add(ExecState* exec, UString::Rep* r)
93 {
94 if (r->identifierTable()) {
95#ifndef NDEBUG
96 checkSameIdentifierTable(exec, r);
97#endif
98 return r;
99 }
100 return addSlowCase(exec, r);
101 }
102 static PassRefPtr<UString::Rep> add(JSGlobalData* globalData, UString::Rep* r)
103 {
104 if (r->identifierTable()) {
105#ifndef NDEBUG
106 checkSameIdentifierTable(globalData, r);
107#endif
108 return r;
109 }
110 return addSlowCase(globalData, r);
111 }
112
113 static PassRefPtr<UString::Rep> addSlowCase(ExecState*, UString::Rep* r);
114 static PassRefPtr<UString::Rep> addSlowCase(JSGlobalData*, UString::Rep* r);
115
116 static void checkSameIdentifierTable(ExecState*, UString::Rep*);
117 static void checkSameIdentifierTable(JSGlobalData*, UString::Rep*);
118 };
119
120 inline bool operator==(const Identifier& a, const Identifier& b)
121 {
122 return Identifier::equal(a, b);
123 }
124
125 inline bool operator!=(const Identifier& a, const Identifier& b)
126 {
127 return !Identifier::equal(a, b);
128 }
129
130 inline bool operator==(const Identifier& a, const char* b)
131 {
132 return Identifier::equal(a, b);
133 }
134
135 IdentifierTable* createIdentifierTable();
136 void deleteIdentifierTable(IdentifierTable*);
137
138} // namespace JSC
139
140#endif // KJS_IDENTIFIER_H
Note: See TracBrowser for help on using the repository browser.