source: webkit/trunk/JavaScriptCore/kjs/internal.h@ 26892

Last change on this file since 26892 was 26892, checked in by darin, 18 years ago

Reviewed by Eric Seidel.

Makes SunSpider 6% faster.

  • kjs/JSImmediate.h: Added toInt32 and toUInt32, with separate versions for 32-bit and 64-bit.
  • kjs/value.h: (KJS::JSValue::getUInt32): Call JSImmediate::toUInt32.
  • kjs/internal.h: Added getInt32.
  • kjs/internal.cpp: (KJS::NumberImp::getInt32): Added. (KJS::NumberImp::getUInt32): Replaced with more-optimal implementation stolen from JSValue.
  • kjs/value.h: (KJS::jsNumber): Marked ALWAYS_INLINE, because this wasn't getting inlined. (KJS::JSValue::getInt32): Added. (KJS::JSValue::getUInt32): Changed to call the new JSImmediate::toUInt32 to avoid converting from float to double. (KJS::JSValue::toInt32): Made inline, separated out the slow case. (KJS::JSValue::toUInt32): Ditto.
  • kjs/value.cpp: (KJS::JSCell::getInt32): Added. (KJS::JSValue::toInt32SlowCase): Renamed from toInt32. Changed to use the new getInt32. Added a faster case for in-range numbers. (KJS::JSValue::toUInt32SlowCase): Ditto. (KJS::JSValue::toUInt16): Added a faster case for in-range numbers.
  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2001 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef INTERNAL_H
25#define INTERNAL_H
26
27#include "JSType.h"
28#include "interpreter.h"
29#include "object.h"
30#include "protect.h"
31#include "scope_chain.h"
32#include "types.h"
33#include "ustring.h"
34
35#include <wtf/Noncopyable.h>
36
37#define I18N_NOOP(s) s
38
39namespace KJS {
40
41 class FunctionPrototype;
42
43 // ---------------------------------------------------------------------------
44 // Primitive impls
45 // ---------------------------------------------------------------------------
46
47 class StringImp : public JSCell {
48 public:
49 StringImp(const UString& v) : val(v) { Collector::reportExtraMemoryCost(v.cost()); }
50 enum HasOtherOwnerType { HasOtherOwner };
51 StringImp(const UString& value, HasOtherOwnerType) : val(value) { }
52 UString value() const { return val; }
53
54 JSType type() const { return StringType; }
55
56 JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
57 bool toBoolean(ExecState *exec) const;
58 double toNumber(ExecState *exec) const;
59 UString toString(ExecState *exec) const;
60 JSObject *toObject(ExecState *exec) const;
61
62 private:
63 UString val;
64 };
65
66 class NumberImp : public JSCell {
67 friend class ConstantValues;
68 friend JSValue *jsNumberCell(double);
69 public:
70 double value() const { return val; }
71
72 JSType type() const { return NumberType; }
73
74 JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
75 bool toBoolean(ExecState *exec) const;
76 double toNumber(ExecState *exec) const;
77 UString toString(ExecState *exec) const;
78 JSObject *toObject(ExecState *exec) const;
79
80 private:
81 NumberImp(double v) : val(v) { }
82
83 virtual bool getInt32(int32_t&) const;
84 virtual bool getUInt32(uint32_t&) const;
85
86 double val;
87 };
88
89
90 /**
91 * @short The "label set" in Ecma-262 spec
92 */
93 class LabelStack : Noncopyable {
94 public:
95 LabelStack()
96 : tos(0)
97 {
98 }
99 ~LabelStack();
100
101 /**
102 * If id is not empty and is not in the stack already, puts it on top of
103 * the stack and returns true, otherwise returns false
104 */
105 bool push(const Identifier &id);
106 /**
107 * Is the id in the stack?
108 */
109 bool contains(const Identifier &id) const;
110 /**
111 * Removes from the stack the last pushed id (what else?)
112 */
113 void pop();
114
115 private:
116 struct StackElem {
117 Identifier id;
118 StackElem *prev;
119 };
120
121 StackElem *tos;
122 };
123
124
125 // ---------------------------------------------------------------------------
126 // Evaluation
127 // ---------------------------------------------------------------------------
128
129 struct AttachedInterpreter;
130 class DebuggerImp {
131 public:
132
133 DebuggerImp() {
134 interps = 0;
135 isAborted = false;
136 }
137
138 void abort() { isAborted = true; }
139 bool aborted() const { return isAborted; }
140
141 AttachedInterpreter *interps;
142 bool isAborted;
143 };
144
145 // helper function for toInteger, toInt32, toUInt32 and toUInt16
146 double roundValue(ExecState *, JSValue *);
147
148#ifndef NDEBUG
149 void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);
150#endif
151
152inline LabelStack::~LabelStack()
153{
154 StackElem *prev;
155 for (StackElem *e = tos; e; e = prev) {
156 prev = e->prev;
157 delete e;
158 }
159}
160
161inline void LabelStack::pop()
162{
163 if (StackElem *e = tos) {
164 tos = e->prev;
165 delete e;
166 }
167}
168
169} // namespace
170
171#endif // INTERNAL_H
Note: See TracBrowser for help on using the repository browser.