]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/lookup.cpp
1 // -*- c-basic-offset: 2 -*-
3 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
4 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
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.
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.
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
25 #include <wtf/Assertions.h>
29 static inline bool keysMatch(const UChar
* c
, unsigned len
, const char* s
)
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
++)
39 static inline const HashEntry
* findEntry(const struct HashTable
* table
, unsigned int hash
,
40 const UChar
* c
, unsigned int len
)
42 ASSERT(table
->type
== 3);
44 const HashEntry
* e
= &table
->entries
[hash
& table
->hashSizeMask
];
51 if (keysMatch(c
, len
, e
->s
))
60 const HashEntry
* Lookup::findEntry(const struct HashTable
* table
, const Identifier
& s
)
62 return KJS::findEntry(table
, s
.ustring().rep()->computedHash(), s
.data(), s
.size());
65 int Lookup::find(const struct HashTable
*table
, const UChar
*c
, unsigned int len
)
67 const HashEntry
*entry
= KJS::findEntry(table
, UString::Rep::computeHash(c
, len
), c
, len
);
69 return entry
->value
.intValue
;
73 int Lookup::find(const struct HashTable
* table
, const Identifier
& s
)
75 const HashEntry
* entry
= KJS::findEntry(table
, s
.ustring().rep()->computedHash(), s
.data(), s
.size());
77 return entry
->value
.intValue
;