]>
Commit | Line | Data |
---|---|---|
93a37866 | 1 | /* |
ed1e77d3 | 2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. |
93a37866 A |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
81345200 | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
93a37866 A |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
81345200 | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
93a37866 A |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #include "config.h" | |
27 | #include "PropertyMapHashTable.h" | |
28 | ||
29 | #include "JSCJSValueInlines.h" | |
30 | #include "JSCellInlines.h" | |
31 | #include "SlotVisitorInlines.h" | |
32 | #include "StructureInlines.h" | |
33 | ||
81345200 A |
34 | #include <wtf/CryptographicallyRandomNumber.h> |
35 | ||
93a37866 A |
36 | namespace JSC { |
37 | ||
ed1e77d3 | 38 | const ClassInfo PropertyTable::s_info = { "PropertyTable", 0, 0, CREATE_METHOD_TABLE(PropertyTable) }; |
93a37866 A |
39 | |
40 | PropertyTable* PropertyTable::create(VM& vm, unsigned initialCapacity) | |
41 | { | |
42 | PropertyTable* table = new (NotNull, allocateCell<PropertyTable>(vm.heap)) PropertyTable(vm, initialCapacity); | |
43 | table->finishCreation(vm); | |
44 | return table; | |
45 | } | |
46 | ||
81345200 | 47 | PropertyTable* PropertyTable::clone(VM& vm, const PropertyTable& other) |
93a37866 | 48 | { |
81345200 | 49 | PropertyTable* table = new (NotNull, allocateCell<PropertyTable>(vm.heap)) PropertyTable(vm, other); |
93a37866 A |
50 | table->finishCreation(vm); |
51 | return table; | |
52 | } | |
53 | ||
81345200 | 54 | PropertyTable* PropertyTable::clone(VM& vm, unsigned initialCapacity, const PropertyTable& other) |
93a37866 | 55 | { |
81345200 | 56 | PropertyTable* table = new (NotNull, allocateCell<PropertyTable>(vm.heap)) PropertyTable(vm, initialCapacity, other); |
93a37866 A |
57 | table->finishCreation(vm); |
58 | return table; | |
59 | } | |
60 | ||
61 | PropertyTable::PropertyTable(VM& vm, unsigned initialCapacity) | |
62 | : JSCell(vm, vm.propertyTableStructure.get()) | |
63 | , m_indexSize(sizeForCapacity(initialCapacity)) | |
64 | , m_indexMask(m_indexSize - 1) | |
65 | , m_index(static_cast<unsigned*>(fastZeroedMalloc(dataSize()))) | |
66 | , m_keyCount(0) | |
67 | , m_deletedCount(0) | |
68 | { | |
69 | ASSERT(isPowerOf2(m_indexSize)); | |
70 | } | |
71 | ||
81345200 | 72 | PropertyTable::PropertyTable(VM& vm, const PropertyTable& other) |
93a37866 A |
73 | : JSCell(vm, vm.propertyTableStructure.get()) |
74 | , m_indexSize(other.m_indexSize) | |
75 | , m_indexMask(other.m_indexMask) | |
76 | , m_index(static_cast<unsigned*>(fastMalloc(dataSize()))) | |
77 | , m_keyCount(other.m_keyCount) | |
78 | , m_deletedCount(other.m_deletedCount) | |
79 | { | |
80 | ASSERT(isPowerOf2(m_indexSize)); | |
81 | ||
82 | memcpy(m_index, other.m_index, dataSize()); | |
83 | ||
84 | iterator end = this->end(); | |
ed1e77d3 | 85 | for (iterator iter = begin(); iter != end; ++iter) |
93a37866 | 86 | iter->key->ref(); |
93a37866 A |
87 | |
88 | // Copy the m_deletedOffsets vector. | |
89 | Vector<PropertyOffset>* otherDeletedOffsets = other.m_deletedOffsets.get(); | |
90 | if (otherDeletedOffsets) | |
ed1e77d3 | 91 | m_deletedOffsets = std::make_unique<Vector<PropertyOffset>>(*otherDeletedOffsets); |
93a37866 A |
92 | } |
93 | ||
81345200 | 94 | PropertyTable::PropertyTable(VM& vm, unsigned initialCapacity, const PropertyTable& other) |
93a37866 A |
95 | : JSCell(vm, vm.propertyTableStructure.get()) |
96 | , m_indexSize(sizeForCapacity(initialCapacity)) | |
97 | , m_indexMask(m_indexSize - 1) | |
98 | , m_index(static_cast<unsigned*>(fastZeroedMalloc(dataSize()))) | |
99 | , m_keyCount(0) | |
100 | , m_deletedCount(0) | |
101 | { | |
102 | ASSERT(isPowerOf2(m_indexSize)); | |
103 | ASSERT(initialCapacity >= other.m_keyCount); | |
104 | ||
105 | const_iterator end = other.end(); | |
106 | for (const_iterator iter = other.begin(); iter != end; ++iter) { | |
107 | ASSERT(canInsert()); | |
108 | reinsert(*iter); | |
109 | iter->key->ref(); | |
93a37866 A |
110 | } |
111 | ||
112 | // Copy the m_deletedOffsets vector. | |
113 | Vector<PropertyOffset>* otherDeletedOffsets = other.m_deletedOffsets.get(); | |
114 | if (otherDeletedOffsets) | |
ed1e77d3 | 115 | m_deletedOffsets = std::make_unique<Vector<PropertyOffset>>(*otherDeletedOffsets); |
93a37866 A |
116 | } |
117 | ||
118 | void PropertyTable::destroy(JSCell* cell) | |
119 | { | |
120 | static_cast<PropertyTable*>(cell)->PropertyTable::~PropertyTable(); | |
121 | } | |
122 | ||
123 | PropertyTable::~PropertyTable() | |
124 | { | |
125 | iterator end = this->end(); | |
126 | for (iterator iter = begin(); iter != end; ++iter) | |
127 | iter->key->deref(); | |
128 | ||
129 | fastFree(m_index); | |
130 | } | |
131 | ||
ed1e77d3 | 132 | } // namespace JSC |
93a37866 | 133 |