]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/PropertyMapHashTable.h
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #ifndef PropertyMapHashTable_h
22 #define PropertyMapHashTable_h
25 #include <wtf/Vector.h>
29 struct PropertyMapEntry
{
33 JSCell
* specificValue
;
36 PropertyMapEntry(UString::Rep
* key
, unsigned attributes
, JSCell
* specificValue
)
39 , attributes(attributes
)
40 , specificValue(specificValue
)
45 PropertyMapEntry(UString::Rep
* key
, unsigned offset
, unsigned attributes
, JSCell
* specificValue
, unsigned index
)
48 , attributes(attributes
)
49 , specificValue(specificValue
)
55 // lastIndexUsed is an ever-increasing index used to identify the order items
56 // were inserted into the property map. It's required that getEnumerablePropertyNames
57 // return the properties in the order they were added for compatibility with other
58 // browsers' JavaScript implementations.
59 struct PropertyMapHashTable
{
63 unsigned deletedSentinelCount
;
64 unsigned lastIndexUsed
;
65 Vector
<unsigned>* deletedOffsets
;
66 unsigned entryIndices
[1];
68 PropertyMapEntry
* entries()
70 // The entries vector comes after the indices vector.
71 // The 0th item in the entries vector is not really used; it has to
72 // have a 0 in its key to allow the hash table lookup to handle deleted
73 // sentinels without any special-case code, but the other fields are unused.
74 return reinterpret_cast<PropertyMapEntry
*>(&entryIndices
[size
]);
77 static size_t allocationSize(unsigned size
)
79 // We never let a hash table get more than half full,
80 // So the number of indices we need is the size of the hash table.
81 // But the number of entries is half that (plus one for the deleted sentinel).
82 return sizeof(PropertyMapHashTable
)
83 + (size
- 1) * sizeof(unsigned)
84 + (1 + size
/ 2) * sizeof(PropertyMapEntry
);
90 #endif // PropertyMapHashTable_h