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

Last change on this file since 12908 was 12317, checked in by mjs, 19 years ago

Reviewed by Tim Hatcher.


  • it's "Franklin Street", not "Franklin Steet"
  • kjs/array_instance.h:
  • kjs/array_object.cpp:
  • kjs/array_object.h:
  • kjs/bool_object.cpp:
  • kjs/bool_object.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/context.h:
  • kjs/date_object.cpp:
  • kjs/date_object.h:
  • kjs/debugger.cpp:
  • kjs/debugger.h:
  • kjs/dtoa.h:
  • kjs/error_object.cpp:
  • kjs/error_object.h:
  • kjs/function.cpp:
  • kjs/function.h:
  • kjs/function_object.cpp:
  • kjs/function_object.h:
  • kjs/grammar.y:
  • kjs/identifier.cpp:
  • kjs/identifier.h:
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lexer.cpp:
  • kjs/lexer.h:
  • kjs/list.cpp:
  • kjs/list.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/math_object.cpp:
  • kjs/math_object.h:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/nodes2string.cpp:
  • kjs/number_object.cpp:
  • kjs/number_object.h:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/object_object.cpp:
  • kjs/object_object.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/property_slot.cpp:
  • kjs/property_slot.h:
  • kjs/reference.cpp:
  • kjs/reference.h:
  • kjs/reference_list.cpp:
  • kjs/reference_list.h:
  • kjs/regexp.cpp:
  • kjs/regexp.h:
  • kjs/regexp_object.cpp:
  • kjs/regexp_object.h:
  • kjs/scope_chain.cpp:
  • kjs/scope_chain.h:
  • kjs/simple_number.h:
  • kjs/string_object.cpp:
  • kjs/string_object.h:
  • kjs/testkjs.cpp:
  • kjs/types.h:
  • kjs/ustring.cpp:
  • kjs/ustring.h:
  • kjs/value.cpp:
  • kjs/value.h:
  • kxmlcore/AlwaysInline.h:
  • kxmlcore/ListRefPtr.h:
  • kxmlcore/PassRefPtr.h:
  • kxmlcore/RefPtr.h:
  • Property svn:eol-style set to native
File size: 2.5 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 * Copyright (C) 2003 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#include "config.h"
24#include <stdio.h>
25#include <string.h>
26
27#include "lookup.h"
28
29#ifdef HAVE_CONFIG_H
30#endif
31
32using namespace KJS;
33
34static inline bool keysMatch(const UChar *c, unsigned len, const char *s)
35{
36 const char* end = s + len;
37 for (; s != end; c++, s++)
38 if (c->uc != (unsigned char)*s)
39 return false;
40 return *s == 0;
41}
42
43static inline const HashEntry* findEntry(const struct HashTable *table, unsigned int hash,
44 const UChar *c, unsigned int len )
45{
46#ifndef NDEBUG
47 if (table->type != 2) {
48 fprintf(stderr, "KJS: Unknown hash table version.\n");
49 return 0;
50 }
51#endif
52 hash %= table->hashSize;
53
54 const HashEntry *e = &table->entries[hash];
55
56 // empty bucket ?
57 if (!e->s)
58 return 0;
59
60 do {
61 // compare strings
62 if (keysMatch(c, len, e->s))
63 return e;
64
65 // try next bucket
66 e = e->next;
67 } while (e);
68 return 0;
69}
70
71const HashEntry* Lookup::findEntry(const struct HashTable *table,
72 const Identifier &s )
73{
74 const HashEntry* entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size());
75 return entry;
76}
77
78int Lookup::find(const struct HashTable *table,
79 const UChar *c, unsigned int len)
80{
81 const HashEntry *entry = ::findEntry(table, UString::Rep::computeHash(c, len), c, len);
82 if (entry)
83 return entry->value;
84 return -1;
85}
86
87int Lookup::find(const struct HashTable *table, const Identifier &s)
88{
89 //printf("looking for:%s\n", s.ascii());
90 const HashEntry *entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size());
91 if (entry)
92 return entry->value;
93 return -1;
94}
Note: See TracBrowser for help on using the repository browser.