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

Last change on this file since 3098 was 2846, checked in by mjs, 23 years ago
  • completed Darin's mostly-fix for 3037795 - Resource use increases when accessing very high index value in array

The two missing pieces were handling sparse properties when
shrinking the array, and when sorting. Thse are now both taken
care of.

  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstanceImp::put): (ArrayInstanceImp::deleteProperty): (ArrayInstanceImp::resizeStorage): (ArrayInstanceImp::setLength): (ArrayInstanceImp::sort): (ArrayInstanceImp::pushUndefinedObjectsToEnd):
  • kjs/identifier.h:
  • kjs/object.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/reference_list.cpp: (ReferenceList::append): (ReferenceList::length):
  • kjs/reference_list.h:
  • kjs/ustring.cpp: (UString::toUInt32):
  • kjs/ustring.h:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2002 Apple Computer, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 */
21
22#ifndef KJS_IDENTIFIER_H
23#define KJS_IDENTIFIER_H
24
25#include "ustring.h"
26
27namespace KJS {
28
29 class Identifier {
30 friend class PropertyMap;
31 public:
32 Identifier() { }
33 Identifier(const char *s) : _ustring(add(s)) { }
34 Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
35 explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
36
37 const UString &ustring() const { return _ustring; }
38 DOM::DOMString string() const;
39 QString qstring() const;
40
41 const UChar *data() const { return _ustring.data(); }
42 int size() const { return _ustring.size(); }
43
44 const char *ascii() const { return _ustring.ascii(); }
45
46 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
47
48 bool isNull() const { return _ustring.isNull(); }
49 bool isEmpty() const { return _ustring.isEmpty(); }
50
51 unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }
52 uint32_t toUInt32(bool *ok) const { return _ustring.toUInt32(ok); }
53 double toDouble() const { return _ustring.toDouble(); }
54
55 static Identifier null;
56
57 friend bool operator==(const Identifier &, const Identifier &);
58 friend bool operator!=(const Identifier &, const Identifier &);
59
60 friend bool operator==(const Identifier &, const char *);
61
62 static void remove(UString::Rep *);
63
64 private:
65 UString _ustring;
66
67 static bool equal(UString::Rep *, const char *);
68 static bool equal(UString::Rep *, const UChar *, int length);
69 static bool equal(UString::Rep *, UString::Rep *);
70
71 static bool equal(const Identifier &a, const Identifier &b)
72 { return a._ustring.rep == b._ustring.rep; }
73 static bool equal(const Identifier &a, const char *b)
74 { return equal(a._ustring.rep, b); }
75
76 static UString::Rep *add(const char *);
77 static UString::Rep *add(const UChar *, int length);
78 static UString::Rep *add(UString::Rep *);
79
80 static void insert(UString::Rep *);
81
82 static void rehash(int newTableSize);
83 static void expand();
84 static void shrink();
85
86 static UString::Rep **_table;
87 static int _tableSize;
88 static int _tableSizeMask;
89 static int _keyCount;
90 };
91
92 inline bool operator==(const Identifier &a, const Identifier &b)
93 { return Identifier::equal(a, b); }
94
95 inline bool operator!=(const Identifier &a, const Identifier &b)
96 { return !Identifier::equal(a, b); }
97
98 inline bool operator==(const Identifier &a, const char *b)
99 { return Identifier::equal(a, b); }
100
101 extern const Identifier argumentsPropertyName;
102 extern const Identifier calleePropertyName;
103 extern const Identifier constructorPropertyName;
104 extern const Identifier lengthPropertyName;
105 extern const Identifier messagePropertyName;
106 extern const Identifier namePropertyName;
107 extern const Identifier prototypePropertyName;
108 extern const Identifier specialPrototypePropertyName;
109 extern const Identifier toLocaleStringPropertyName;
110 extern const Identifier toStringPropertyName;
111 extern const Identifier valueOfPropertyName;
112
113}
114
115#endif
Note: See TracBrowser for help on using the repository browser.