OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 13 matching lines...) Expand all Loading... |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/dom/StaticNodeList.h" | 30 #include "core/dom/StaticNodeList.h" |
31 | 31 |
32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
33 | 33 |
| 34 #include <v8.h> |
| 35 |
34 namespace WebCore { | 36 namespace WebCore { |
35 | 37 |
| 38 PassRefPtr<StaticNodeList> StaticNodeList::adopt(Vector<RefPtr<Node> >& nodes) |
| 39 { |
| 40 RefPtr<StaticNodeList> nodeList = adoptRef(new StaticNodeList); |
| 41 nodeList->m_nodes.swap(nodes); |
| 42 v8::V8::AdjustAmountOfExternalAllocatedMemory(nodeList->m_nodes.capacity() *
sizeof(RefPtr<Node>)); |
| 43 return nodeList.release(); |
| 44 } |
| 45 |
| 46 StaticNodeList::~StaticNodeList() |
| 47 { |
| 48 v8::V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(m_nodes.capa
city() * sizeof(RefPtr<Node>))); |
| 49 } |
| 50 |
36 unsigned StaticNodeList::length() const | 51 unsigned StaticNodeList::length() const |
37 { | 52 { |
38 return m_nodes.size(); | 53 return m_nodes.size(); |
39 } | 54 } |
40 | 55 |
41 Node* StaticNodeList::item(unsigned index) const | 56 Node* StaticNodeList::item(unsigned index) const |
42 { | 57 { |
43 if (index < m_nodes.size()) | 58 if (index < m_nodes.size()) |
44 return m_nodes[index].get(); | 59 return m_nodes[index].get(); |
45 return 0; | 60 return 0; |
46 } | 61 } |
47 | 62 |
48 Node* StaticNodeList::namedItem(const AtomicString& elementId) const | 63 Node* StaticNodeList::namedItem(const AtomicString& elementId) const |
49 { | 64 { |
50 size_t length = m_nodes.size(); | 65 size_t length = m_nodes.size(); |
51 for (size_t i = 0; i < length; ++i) { | 66 for (size_t i = 0; i < length; ++i) { |
52 Node* node = m_nodes[i].get(); | 67 Node* node = m_nodes[i].get(); |
53 if (node->isElementNode() && toElement(node)->getIdAttribute() == elemen
tId) | 68 if (node->isElementNode() && toElement(node)->getIdAttribute() == elemen
tId) |
54 return node; | 69 return node; |
55 } | 70 } |
56 | 71 |
57 return 0; | 72 return 0; |
58 } | 73 } |
59 | 74 |
60 } // namespace WebCore | 75 } // namespace WebCore |
OLD | NEW |