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

Last change on this file since 31147 was 31147, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-03-18 Darin Adler <Darin Adler>

Reviewed by Maciej.

  • Speed up JavaScript built-in properties by changing the hash table to take advantage of the identifier objects

5% speedup for Acid3 test 26

  • JavaScriptCore.exp: Updated.
  • kjs/create_hash_table: Compute size of hash table large enough so that there are no collisions, but don't generate the hash table.
  • kjs/identifier.h: Made the add function that returns a PassRefPtr public.
  • kjs/lexer.cpp: (KJS::Lexer::lex): Updated for change to HashTable interface.
  • kjs/lookup.cpp: (KJS::HashTable::changeKeysToIdentifiers): Added. Finds the identifier for each property so the equality comparision can be done with pointer comparision.
  • kjs/lookup.h: Made the key be a union of char* with UString::Rep* so it can hold identifiers. Added a keysAreIdentifiers flag to the HashTable. Changed the Lookup functions to be member functions of HashTable instead.
  • kjs/object.cpp: (KJS::JSObject::deleteProperty): Update for change to HashTable. (KJS::JSObject::findPropertyHashEntry): Ditto. (KJS::JSObject::getPropertyAttributes): Ditto. (KJS::JSObject::getPropertyNames): Ditto.

WebCore:

2008-03-18 Darin Adler <Darin Adler>

Reviewed by Maciej.

  • Speed up JavaScript built-in properties by changing the hash table to take advantage of the identifier objects

5% speedup for Acid3 test 26

  • bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::getOwnPropertySlot): Update for change to HashTable. (WebCore::JSDOMWindowBase::put): Ditto.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customGetOwnPropertySlot): Ditto.
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBase::getOwnPropertySlot): Ditto.
  • bindings/js/JSHistoryCustom.cpp: (WebCore::JSHistory::customGetOwnPropertySlot): Ditto.
  • bindings/js/JSLocation.cpp: (WebCore::JSLocation::customGetOwnPropertySlot): Ditto. (WebCore::JSLocation::put): Ditto.
  • bindings/js/kjs_binding.cpp: (WebCore::nonCachingStaticFunctionGetter): Ditto.
  • bindings/scripts/CodeGeneratorJS.pm: Same changes as in the create_hash_table script.
  • Property svn:eol-style set to native
File size: 3.9 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 "ustring.h"
25
26namespace KJS {
27
28 class Identifier {
29 friend class PropertyMap;
30 public:
31 Identifier() { }
32 Identifier(const char* s) : _ustring(add(s)) { }
33 Identifier(const UChar* s, int length) : _ustring(add(s, length)) { }
34 explicit Identifier(UString::Rep* rep) : _ustring(add(rep)) { }
35 explicit Identifier(const UString& s) : _ustring(add(s.rep())) { }
36
37 // Special constructor for cases where we overwrite an object in place.
38 Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { }
39
40 const UString& ustring() const { return _ustring; }
41 DOM::DOMString domString() const;
42
43 const UChar* data() const { return _ustring.data(); }
44 int size() const { return _ustring.size(); }
45
46 const char* ascii() const { return _ustring.ascii(); }
47
48 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
49
50 bool isNull() const { return _ustring.isNull(); }
51 bool isEmpty() const { return _ustring.isEmpty(); }
52
53 uint32_t toUInt32(bool* ok) const { return _ustring.toUInt32(ok); }
54 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); };
55 uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); }
56 unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); }
57 double toDouble() const { return _ustring.toDouble(); }
58
59 friend bool operator==(const Identifier&, const Identifier&);
60 friend bool operator!=(const Identifier&, const Identifier&);
61
62 friend bool operator==(const Identifier&, const char*);
63
64 static void remove(UString::Rep*);
65
66 static bool equal(const UString::Rep*, const char*);
67 static bool equal(const UString::Rep*, const UChar*, int length);
68 static bool equal(const UString::Rep*, const UString::Rep*);
69
70 static PassRefPtr<UString::Rep> add(const char*);
71
72 private:
73 UString _ustring;
74
75 static bool equal(const Identifier& a, const Identifier& b)
76 { return a._ustring.rep() == b._ustring.rep(); }
77 static bool equal(const Identifier& a, const char* b)
78 { return equal(a._ustring.rep(), b); }
79
80 static PassRefPtr<UString::Rep> add(const UChar*, int length);
81 static PassRefPtr<UString::Rep> add(UString::Rep* r)
82 {
83 if (r->isIdentifier)
84 return r;
85 return addSlowCase(r);
86 }
87 static PassRefPtr<UString::Rep> addSlowCase(UString::Rep *r);
88 };
89
90 inline bool operator==(const Identifier& a, const Identifier& b)
91 { return Identifier::equal(a, b); }
92
93 inline bool operator!=(const Identifier& a, const Identifier& b)
94 { return !Identifier::equal(a, b); }
95
96 inline bool operator==(const Identifier& a, const char* b)
97 { return Identifier::equal(a, b); }
98
99} // namespace KJS
100
101#endif // KJS_IDENTIFIER_H
Note: See TracBrowser for help on using the repository browser.