source: webkit/trunk/JavaScriptCore/kjs/lookup.cpp@ 29059

Last change on this file since 29059 was 27608, checked in by [email protected], 18 years ago

JavaScriptCore:

Reviewed by Darin.

Convert JavaScript internal function objects to use one class per
function. This avoids a switch statement inside what used to be
the shared function classes and will allow Shark to better analyze
the code.

To make this switch, the value property of the HashEntry was changed
to a union of an intptr_t (which is used to continue handle valueGetters)
and function pointer which points to a static constructor for the
individual new function objects.

SunSpider claims this is a 0.5% speedup.

  • kjs/array_object.cpp: (KJS::ArrayPrototype::getOwnPropertySlot): (KJS::getProperty): (KJS::ArrayProtoFuncToString::callAsFunction): (KJS::ArrayProtoFuncToLocaleString::callAsFunction): (KJS::ArrayProtoFuncJoin::callAsFunction): (KJS::ArrayProtoFuncConcat::callAsFunction): (KJS::ArrayProtoFuncPop::callAsFunction): (KJS::ArrayProtoFuncPush::callAsFunction): (KJS::ArrayProtoFuncReverse::callAsFunction): (KJS::ArrayProtoFuncShift::callAsFunction): (KJS::ArrayProtoFuncSlice::callAsFunction): (KJS::ArrayProtoFuncSort::callAsFunction): (KJS::ArrayProtoFuncSplice::callAsFunction): (KJS::ArrayProtoFuncUnShift::callAsFunction): (KJS::ArrayProtoFuncFilter::callAsFunction): (KJS::ArrayProtoFuncMap::callAsFunction): (KJS::ArrayProtoFuncEvery::callAsFunction): (KJS::ArrayProtoFuncForEach::callAsFunction): (KJS::ArrayProtoFuncSome::callAsFunction): (KJS::ArrayProtoFuncIndexOf::callAsFunction): (KJS::ArrayProtoFuncLastIndexOf::callAsFunction):
  • kjs/array_object.h: (KJS::ArrayPrototype::classInfo):
  • kjs/create_hash_table:
  • kjs/date_object.cpp: (KJS::DatePrototype::getOwnPropertySlot): (KJS::DateProtoFuncToString::callAsFunction): (KJS::DateProtoFuncToUTCString::callAsFunction): (KJS::DateProtoFuncToDateString::callAsFunction): (KJS::DateProtoFuncToTimeString::callAsFunction): (KJS::DateProtoFuncToLocaleString::callAsFunction): (KJS::DateProtoFuncToLocaleDateString::callAsFunction): (KJS::DateProtoFuncToLocaleTimeString::callAsFunction): (KJS::DateProtoFuncValueOf::callAsFunction): (KJS::DateProtoFuncGetTime::callAsFunction): (KJS::DateProtoFuncGetFullYear::callAsFunction): (KJS::DateProtoFuncGetUTCFullYear::callAsFunction): (KJS::DateProtoFuncToGMTString::callAsFunction): (KJS::DateProtoFuncGetMonth::callAsFunction): (KJS::DateProtoFuncGetUTCMonth::callAsFunction): (KJS::DateProtoFuncGetDate::callAsFunction): (KJS::DateProtoFuncGetUTCDate::callAsFunction): (KJS::DateProtoFuncGetDay::callAsFunction): (KJS::DateProtoFuncGetUTCDay::callAsFunction): (KJS::DateProtoFuncGetHours::callAsFunction): (KJS::DateProtoFuncGetUTCHours::callAsFunction): (KJS::DateProtoFuncGetMinutes::callAsFunction): (KJS::DateProtoFuncGetUTCMinutes::callAsFunction): (KJS::DateProtoFuncGetSeconds::callAsFunction): (KJS::DateProtoFuncGetUTCSeconds::callAsFunction): (KJS::DateProtoFuncGetMilliSeconds::callAsFunction): (KJS::DateProtoFuncGetUTCMilliseconds::callAsFunction): (KJS::DateProtoFuncGetTimezoneOffset::callAsFunction): (KJS::DateProtoFuncSetTime::callAsFunction): (KJS::DateProtoFuncSetMilliSeconds::callAsFunction): (KJS::DateProtoFuncSetUTCMilliseconds::callAsFunction): (KJS::DateProtoFuncSetSeconds::callAsFunction): (KJS::DateProtoFuncSetUTCSeconds::callAsFunction): (KJS::DateProtoFuncSetMinutes::callAsFunction): (KJS::DateProtoFuncSetUTCMinutes::callAsFunction): (KJS::DateProtoFuncSetHours::callAsFunction): (KJS::DateProtoFuncSetUTCHours::callAsFunction): (KJS::DateProtoFuncSetDate::callAsFunction): (KJS::DateProtoFuncSetUTCDate::callAsFunction): (KJS::DateProtoFuncSetMonth::callAsFunction): (KJS::DateProtoFuncSetUTCMonth::callAsFunction): (KJS::DateProtoFuncSetFullYear::callAsFunction): (KJS::DateProtoFuncSetUTCFullYear::callAsFunction): (KJS::DateProtoFuncSetYear::callAsFunction): (KJS::DateProtoFuncGetYear::callAsFunction):
  • kjs/date_object.h:
  • kjs/lookup.cpp: (KJS::Lookup::find):
  • kjs/lookup.h: (KJS::HashEntry::): (KJS::staticFunctionGetter): (KJS::staticValueGetter): (KJS::getStaticPropertySlot): (KJS::getStaticFunctionSlot): (KJS::lookupPut):
  • kjs/math_object.cpp: (KJS::MathObjectImp::getOwnPropertySlot): (KJS::MathProtoFuncAbs::callAsFunction): (KJS::MathProtoFuncACos::callAsFunction): (KJS::MathProtoFuncASin::callAsFunction): (KJS::MathProtoFuncATan::callAsFunction): (KJS::MathProtoFuncATan2::callAsFunction): (KJS::MathProtoFuncCeil::callAsFunction): (KJS::MathProtoFuncCos::callAsFunction): (KJS::MathProtoFuncExp::callAsFunction): (KJS::MathProtoFuncFloor::callAsFunction): (KJS::MathProtoFuncLog::callAsFunction): (KJS::MathProtoFuncMax::callAsFunction): (KJS::MathProtoFuncMin::callAsFunction): (KJS::MathProtoFuncPow::callAsFunction): (KJS::MathProtoFuncRandom::callAsFunction): (KJS::MathProtoFuncRound::callAsFunction): (KJS::MathProtoFuncSin::callAsFunction): (KJS::MathProtoFuncSqrt::callAsFunction): (KJS::MathProtoFuncTan::callAsFunction):
  • kjs/math_object.h: (KJS::MathObjectImp::classInfo): (KJS::MathObjectImp::):
  • kjs/string_object.cpp: (KJS::StringPrototype::getOwnPropertySlot): (KJS::StringProtoFuncToString::callAsFunction): (KJS::StringProtoFuncValueOf::callAsFunction): (KJS::StringProtoFuncCharAt::callAsFunction): (KJS::StringProtoFuncCharCodeAt::callAsFunction): (KJS::StringProtoFuncConcat::callAsFunction): (KJS::StringProtoFuncIndexOf::callAsFunction): (KJS::StringProtoFuncLastIndexOf::callAsFunction): (KJS::StringProtoFuncMatch::callAsFunction): (KJS::StringProtoFuncSearch::callAsFunction): (KJS::StringProtoFuncReplace::callAsFunction): (KJS::StringProtoFuncSlice::callAsFunction): (KJS::StringProtoFuncSplit::callAsFunction): (KJS::StringProtoFuncSubstr::callAsFunction): (KJS::StringProtoFuncSubstring::callAsFunction): (KJS::StringProtoFuncToLowerCase::callAsFunction): (KJS::StringProtoFuncToUpperCase::callAsFunction): (KJS::StringProtoFuncToLocaleLowerCase::callAsFunction): (KJS::StringProtoFuncToLocaleUpperCase::callAsFunction): (KJS::StringProtoFuncLocaleCompare::callAsFunction): (KJS::StringProtoFuncBig::callAsFunction): (KJS::StringProtoFuncSmall::callAsFunction): (KJS::StringProtoFuncBlink::callAsFunction): (KJS::StringProtoFuncBold::callAsFunction): (KJS::StringProtoFuncFixed::callAsFunction): (KJS::StringProtoFuncItalics::callAsFunction): (KJS::StringProtoFuncStrike::callAsFunction): (KJS::StringProtoFuncSub::callAsFunction): (KJS::StringProtoFuncSup::callAsFunction): (KJS::StringProtoFuncFontcolor::callAsFunction): (KJS::StringProtoFuncFontsize::callAsFunction): (KJS::StringProtoFuncAnchor::callAsFunction): (KJS::StringProtoFuncLink::callAsFunction):
  • kjs/string_object.h:

WebCore:

Reviewed by Darin.

Convert JavaScript internal function objects to use one class per
function. This avoids a switch statement inside what used to be
the shared function classes and will allow Shark to better analyze
the code.

To make this switch, the value property of the HashEntry was changed
to a union of an intptr_t (which is used to continue handle valueGetters)
and function pointer which points to a static constructor for the
individual new function objects.

SunSpider claims this is a 0.5% speedup.

  • On the WebCore side, I updated CodeGeneratorJS.pm to generate the new classes and hand updated the remain non-generated (groan) classes.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customGetOwnPropertySlot):
  • bindings/js/JSEventTargetNode.cpp: (WebCore::JSEventTargetNodePrototypeFunctionAddEventListener::callAsFunction): (WebCore::JSEventTargetNodePrototypeFunctionRemoveEventListener::callAsFunction): (WebCore::JSEventTargetNodePrototypeFunctionDispatchEvent::callAsFunction):
  • bindings/js/JSEventTargetNode.h:
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBaseFunctionSetSelectionRange::callAsFunction): (WebCore::JSHTMLInputElementBase::getOwnPropertySlot):
  • bindings/js/JSHTMLInputElementBase.h: (WebCore::JSHTMLInputElementBase::):
  • bindings/js/JSXMLHttpRequest.cpp: (KJS::JSXMLHttpRequestPrototypeFunctionAbort::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionGetAllResponseHeaders::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionGetResponseHeader::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionOpen::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionSend::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionSetRequestHeader::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionOverrideMIMEType::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionAddEventListener::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionRemoveEventListener::callAsFunction): (KJS::JSXMLHttpRequestPrototypeFunctionDispatchEvent::callAsFunction):
  • bindings/js/JSXMLHttpRequest.h: (KJS::JSXMLHttpRequest::impl):
  • bindings/js/JSXSLTProcessor.cpp: (KJS::JSXSLTProcessorPrototypeFunctionImportStylesheet::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionTransformToFragment::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionTransformToDocument::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionSetParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionGetParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionRemoveParameter::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionClearParameters::callAsFunction): (KJS::JSXSLTProcessorPrototypeFunctionReset::callAsFunction):
  • bindings/js/JSXSLTProcessor.h:
  • bindings/js/kjs_events.cpp: (WebCore::JSClipboardPrototypeFunctionClearData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionGetData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionSetData::callAsFunction): (WebCore::JSClipboardPrototypeFunctionSetDragImage::callAsFunction):
  • bindings/js/kjs_events.h:
  • bindings/js/kjs_navigator.cpp: (KJS::Plugins::): (KJS::Navigator::getOwnPropertySlot): (KJS::Plugins::getOwnPropertySlot): (KJS::PluginsFunctionRefresh::callAsFunction): (KJS::NavigatorProtoFuncJavaEnabled::callAsFunction):
  • bindings/js/kjs_navigator.h: (KJS::Navigator::):
  • bindings/js/kjs_window.cpp: (KJS::Window::getOwnPropertySlot): (KJS::Window::put): (KJS::WindowProtoFuncAToB::callAsFunction): (KJS::WindowProtoFuncBToA::callAsFunction): (KJS::WindowProtoFuncOpen::callAsFunction): (KJS::WindowProtoFuncScrollBy::callAsFunction): (KJS::WindowProtoFuncScrollTo::callAsFunction): (KJS::WindowProtoFuncMoveBy::callAsFunction): (KJS::WindowProtoFuncMoveTo::callAsFunction): (KJS::WindowProtoFuncResizeBy::callAsFunction): (KJS::WindowProtoFuncResizeTo::callAsFunction): (KJS::WindowProtoFuncSetTimeout::callAsFunction): (KJS::WindowProtoFuncClearTimeout::callAsFunction): (KJS::WindowProtoFuncSetInterval::callAsFunction): (KJS::WindowProtoFuncAddEventListener::callAsFunction): (KJS::WindowProtoFuncRemoveEventListener::callAsFunction): (KJS::WindowProtoFuncShowModalDialog::callAsFunction): (KJS::WindowProtoFuncNotImplemented::callAsFunction): (KJS::Location::getOwnPropertySlot): (KJS::Location::put): (KJS::LocationProtoFuncReplace::callAsFunction): (KJS::LocationProtoFuncReload::callAsFunction): (KJS::LocationProtoFuncAssign::callAsFunction): (KJS::LocationProtoFuncToString::callAsFunction):
  • bindings/js/kjs_window.h: (KJS::Window::):
  • bindings/scripts/CodeGeneratorJS.pm:
  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2000 Harri Porten ([email protected])
4 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#include "config.h"
23#include "lookup.h"
24
25#include <wtf/Assertions.h>
26
27namespace KJS {
28
29static inline bool keysMatch(const UChar* c, unsigned len, const char* s)
30{
31 // FIXME: This can run off the end of |s| if |c| has a U+0000 character in it.
32 const char* end = s + len;
33 for (; s != end; c++, s++)
34 if (c->uc != *s)
35 return false;
36 return *s == 0;
37}
38
39static inline const HashEntry* findEntry(const struct HashTable* table, unsigned int hash,
40 const UChar* c, unsigned int len)
41{
42 ASSERT(table->type == 3);
43
44 const HashEntry* e = &table->entries[hash & table->hashSizeMask];
45
46 if (!e->s)
47 return 0;
48
49 do {
50 // compare strings
51 if (keysMatch(c, len, e->s))
52 return e;
53
54 // try next bucket
55 e = e->next;
56 } while (e);
57 return 0;
58}
59
60const HashEntry* Lookup::findEntry(const struct HashTable* table, const Identifier& s)
61{
62 return KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
63}
64
65int Lookup::find(const struct HashTable *table, const UChar *c, unsigned int len)
66{
67 const HashEntry *entry = KJS::findEntry(table, UString::Rep::computeHash(c, len), c, len);
68 if (entry)
69 return entry->value.intValue;
70 return -1;
71}
72
73int Lookup::find(const struct HashTable* table, const Identifier& s)
74{
75 const HashEntry* entry = KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
76 if (entry)
77 return entry->value.intValue;
78 return -1;
79}
80
81}
Note: See TracBrowser for help on using the repository browser.