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

Last change on this file since 2779 was 2760, checked in by darin, 23 years ago

JavaScriptCore:

  • a first step towards atomic identifiers in JavaScript

Most places that work with identifiers now use Identifier
instead of UString.

  • kjs/identifier.cpp: Added.
  • kjs/identifier.h: Added.
  • JavaScriptCore.pbproj/project.pbxproj: Added files.
  • kjs/array_object.cpp:
  • kjs/array_object.h:
  • kjs/completion.cpp:
  • kjs/completion.h:
  • kjs/date_object.cpp:
  • kjs/date_object.h:
  • kjs/function.cpp:
  • kjs/function.h:
  • kjs/function_object.cpp:
  • kjs/grammar.cpp:
  • kjs/grammar.cpp.h:
  • kjs/grammar.h:
  • kjs/grammar.y:
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/lexer.cpp:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/math_object.cpp:
  • kjs/math_object.h:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/number_object.cpp:
  • kjs/number_object.h:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/reference.cpp:
  • kjs/reference.h:
  • kjs/regexp_object.cpp:
  • kjs/regexp_object.h:
  • kjs/string_object.cpp:
  • kjs/string_object.h:

WebCore:

  • a first step towards atomic identifiers in JavaScript

Most places that work with identifiers now use Identifier
instead of UString.

  • khtml/ecma/kjs_binding.cpp:
  • khtml/ecma/kjs_binding.h:
  • khtml/ecma/kjs_css.cpp:
  • khtml/ecma/kjs_css.h:
  • khtml/ecma/kjs_dom.cpp:
  • khtml/ecma/kjs_dom.h:
  • khtml/ecma/kjs_events.cpp:
  • khtml/ecma/kjs_events.h:
  • khtml/ecma/kjs_html.cpp:
  • khtml/ecma/kjs_html.h:
  • khtml/ecma/kjs_navigator.cpp:
  • khtml/ecma/kjs_navigator.h:
  • khtml/ecma/kjs_range.cpp:
  • khtml/ecma/kjs_range.h:
  • khtml/ecma/kjs_traversal.cpp:
  • khtml/ecma/kjs_traversal.h:
  • khtml/ecma/kjs_views.cpp:
  • khtml/ecma/kjs_views.h:
  • khtml/ecma/kjs_window.cpp:
  • khtml/ecma/kjs_window.h:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <stdio.h>
23#include <string.h>
24
25#include "lookup.h"
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31using namespace KJS;
32
33static bool keysMatch(const UChar *c, unsigned len, const char *s)
34{
35 for (unsigned i = 0; i != len; i++, c++, s++)
36 if (c->unicode() != (unsigned char)*s)
37 return false;
38 return *s == 0;
39}
40
41const HashEntry* Lookup::findEntry( const struct HashTable *table,
42 const UChar *c, unsigned int len )
43{
44#ifndef NDEBUG
45 if (table->type != 2) {
46 fprintf(stderr, "KJS: Unknown hash table version.\n");
47 return 0;
48 }
49#endif
50
51 int h = hash(c, len) % table->hashSize;
52 const HashEntry *e = &table->entries[h];
53
54 // empty bucket ?
55 if (!e->s)
56 return 0;
57
58 do {
59 // compare strings
60 if (keysMatch(c, len, e->s))
61 return e;
62 // try next bucket
63 e = e->next;
64 } while (e);
65
66 return 0;
67}
68
69const HashEntry* Lookup::findEntry( const struct HashTable *table,
70 const Identifier &s )
71{
72 return findEntry( table, s.data(), s.size() );
73}
74
75int Lookup::find(const struct HashTable *table,
76 const UChar *c, unsigned int len)
77{
78 const HashEntry *entry = findEntry( table, c, len );
79 if (entry)
80 return entry->value;
81 return -1;
82}
83
84int Lookup::find(const struct HashTable *table, const Identifier &s)
85{
86 return find(table, s.data(), s.size());
87}
88
89unsigned int Lookup::hash(const UChar *c, unsigned int len)
90{
91 unsigned int val = 0;
92 // ignoring higher byte
93 for (unsigned int i = 0; i < len; i++, c++)
94 val += c->low();
95
96 return val;
97}
98
99unsigned int Lookup::hash(const Identifier &key)
100{
101 return hash(key.data(), key.size());
102}
103
104unsigned int Lookup::hash(const char *s)
105{
106 unsigned int val = 0;
107 while (*s)
108 val += *s++;
109
110 return val;
111}
Note: See TracBrowser for help on using the repository browser.