]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. | |
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 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
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 | ||
34 | #include <wtf/CryptographicallyRandomNumber.h> | |
35 | ||
36 | namespace JSC { | |
37 | ||
38 | const ClassInfo PropertyTable::s_info = { "PropertyTable", 0, 0, CREATE_METHOD_TABLE(PropertyTable) }; | |
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 | ||
47 | PropertyTable* PropertyTable::clone(VM& vm, const PropertyTable& other) | |
48 | { | |
49 | PropertyTable* table = new (NotNull, allocateCell<PropertyTable>(vm.heap)) PropertyTable(vm, other); | |
50 | table->finishCreation(vm); | |
51 | return table; | |
52 | } | |
53 | ||
54 | PropertyTable* PropertyTable::clone(VM& vm, unsigned initialCapacity, const PropertyTable& other) | |
55 | { | |
56 | PropertyTable* table = new (NotNull, allocateCell<PropertyTable>(vm.heap)) PropertyTable(vm, initialCapacity, other); | |
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 | ||
72 | PropertyTable::PropertyTable(VM& vm, const PropertyTable& other) | |
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(); | |
85 | for (iterator iter = begin(); iter != end; ++iter) | |
86 | iter->key->ref(); | |
87 | ||
88 | // Copy the m_deletedOffsets vector. | |
89 | Vector<PropertyOffset>* otherDeletedOffsets = other.m_deletedOffsets.get(); | |
90 | if (otherDeletedOffsets) | |
91 | m_deletedOffsets = std::make_unique<Vector<PropertyOffset>>(*otherDeletedOffsets); | |
92 | } | |
93 | ||
94 | PropertyTable::PropertyTable(VM& vm, unsigned initialCapacity, const PropertyTable& other) | |
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(); | |
110 | } | |
111 | ||
112 | // Copy the m_deletedOffsets vector. | |
113 | Vector<PropertyOffset>* otherDeletedOffsets = other.m_deletedOffsets.get(); | |
114 | if (otherDeletedOffsets) | |
115 | m_deletedOffsets = std::make_unique<Vector<PropertyOffset>>(*otherDeletedOffsets); | |
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 | ||
132 | } // namespace JSC | |
133 |