OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/heap/CallbackStack.h" | 5 #include "platform/heap/CallbackStack.h" |
| 6 #include "wtf/Partitions.h" |
6 | 7 |
7 namespace blink { | 8 namespace blink { |
8 | 9 |
| 10 CallbackStack::Block::Block(Block* next, size_t blockSize) |
| 11 : m_blockSize(blockSize) |
| 12 { |
| 13 m_buffer = static_cast<Item*>(WTF::Partitions::fastMalloc(blockSize * sizeof
(Item), "CallbackStack::Block")); |
| 14 m_limit = &(m_buffer[m_blockSize]); |
| 15 m_current = &(m_buffer[0]); |
| 16 m_next = next; |
| 17 clearUnused(); |
| 18 } |
| 19 |
| 20 CallbackStack::Block::~Block() |
| 21 { |
| 22 clearUnused(); |
| 23 m_limit = nullptr; |
| 24 m_current = nullptr; |
| 25 m_next = nullptr; |
| 26 WTF::Partitions::fastFree(m_buffer); |
| 27 } |
| 28 |
9 void CallbackStack::Block::clear() | 29 void CallbackStack::Block::clear() |
10 { | 30 { |
11 m_current = &m_buffer[0]; | 31 m_current = &m_buffer[0]; |
12 m_next = nullptr; | 32 m_next = nullptr; |
13 clearUnused(); | 33 clearUnused(); |
14 } | 34 } |
15 | 35 |
16 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) | 36 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) |
17 { | 37 { |
18 // This loop can tolerate entries being added by the callbacks after | 38 // This loop can tolerate entries being added by the callbacks after |
(...skipping 12 matching lines...) Expand all Loading... |
31 if (item->object() == object) | 51 if (item->object() == object) |
32 return true; | 52 return true; |
33 } | 53 } |
34 return false; | 54 return false; |
35 } | 55 } |
36 #endif | 56 #endif |
37 | 57 |
38 void CallbackStack::Block::clearUnused() | 58 void CallbackStack::Block::clearUnused() |
39 { | 59 { |
40 #if ENABLE(ASSERT) | 60 #if ENABLE(ASSERT) |
41 for (size_t i = 0; i < blockSize; i++) | 61 for (size_t i = 0; i < m_blockSize; i++) |
42 m_buffer[i] = Item(0, 0); | 62 m_buffer[i] = Item(0, 0); |
43 #endif | 63 #endif |
44 } | 64 } |
45 | 65 |
46 CallbackStack::CallbackStack() : m_first(new Block(0)), m_last(m_first) | 66 CallbackStack::CallbackStack(size_t reservedStackSize) |
| 67 : m_first(new Block(nullptr, reservedStackSize)) |
| 68 , m_last(m_first) |
47 { | 69 { |
48 } | 70 } |
49 | 71 |
50 CallbackStack::~CallbackStack() | 72 CallbackStack::~CallbackStack() |
51 { | 73 { |
52 clear(); | 74 clear(); |
53 delete m_first; | 75 delete m_first; |
54 m_first = nullptr; | 76 m_first = nullptr; |
55 m_last = nullptr; | 77 m_last = nullptr; |
56 } | 78 } |
(...skipping 10 matching lines...) Expand all Loading... |
67 } | 89 } |
68 | 90 |
69 bool CallbackStack::isEmpty() const | 91 bool CallbackStack::isEmpty() const |
70 { | 92 { |
71 return hasJustOneBlock() && m_first->isEmptyBlock(); | 93 return hasJustOneBlock() && m_first->isEmptyBlock(); |
72 } | 94 } |
73 | 95 |
74 CallbackStack::Item* CallbackStack::allocateEntrySlow() | 96 CallbackStack::Item* CallbackStack::allocateEntrySlow() |
75 { | 97 { |
76 ASSERT(!m_first->allocateEntry()); | 98 ASSERT(!m_first->allocateEntry()); |
77 m_first = new Block(m_first); | 99 m_first = new Block(m_first, m_first->blockSize() * 2); |
78 return m_first->allocateEntry(); | 100 return m_first->allocateEntry(); |
79 } | 101 } |
80 | 102 |
81 CallbackStack::Item* CallbackStack::popSlow() | 103 CallbackStack::Item* CallbackStack::popSlow() |
82 { | 104 { |
83 ASSERT(m_first->isEmptyBlock()); | 105 ASSERT(m_first->isEmptyBlock()); |
84 | 106 |
85 for (;;) { | 107 for (;;) { |
86 Block* next = m_first->next(); | 108 Block* next = m_first->next(); |
87 if (!next) { | 109 if (!next) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 157 { |
136 for (Block* current = m_first; current; current = current->next()) { | 158 for (Block* current = m_first; current; current = current->next()) { |
137 if (current->hasCallbackForObject(object)) | 159 if (current->hasCallbackForObject(object)) |
138 return true; | 160 return true; |
139 } | 161 } |
140 return false; | 162 return false; |
141 } | 163 } |
142 #endif | 164 #endif |
143 | 165 |
144 } // namespace blink | 166 } // namespace blink |
OLD | NEW |