]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/ArgList.cpp
0b5d958b6aaa35f61ec0517f50e20d57ea93cd53
[apple/javascriptcore.git] / runtime / ArgList.cpp
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 *
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.
8 *
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.
13 *
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.
18 *
19 */
20
21 #include "config.h"
22 #include "ArgList.h"
23
24 #include "JSValue.h"
25 #include "JSCell.h"
26
27 using std::min;
28
29 namespace JSC {
30
31 void ArgList::getSlice(int startIndex, ArgList& result) const
32 {
33 if (startIndex <= 0 || static_cast<unsigned>(startIndex) >= m_argCount) {
34 result = ArgList(m_args, 0);
35 return;
36 }
37 result = ArgList(m_args + startIndex, m_argCount - startIndex);
38 }
39
40 void MarkedArgumentBuffer::markLists(ListSet& markSet)
41 {
42 ListSet::iterator end = markSet.end();
43 for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
44 MarkedArgumentBuffer* list = *it;
45
46 iterator end2 = list->end();
47 for (iterator it2 = list->begin(); it2 != end2; ++it2)
48 if (!(*it2).marked())
49 (*it2).mark();
50 }
51 }
52
53 void MarkedArgumentBuffer::slowAppend(JSValue v)
54 {
55 // As long as our size stays within our Vector's inline
56 // capacity, all our values are allocated on the stack, and
57 // therefore don't need explicit marking. Once our size exceeds
58 // our Vector's inline capacity, though, our values move to the
59 // heap, where they do need explicit marking.
60 if (!m_markSet) {
61 // We can only register for explicit marking once we know which heap
62 // is the current one, i.e., when a non-immediate value is appended.
63 if (Heap* heap = Heap::heap(v)) {
64 ListSet& markSet = heap->markListSet();
65 markSet.add(this);
66 m_markSet = &markSet;
67 }
68 }
69
70 if (m_vector.size() < m_vector.capacity()) {
71 m_vector.uncheckedAppend(v);
72 return;
73 }
74
75 // 4x growth would be excessive for a normal vector, but it's OK for Lists
76 // because they're short-lived.
77 m_vector.reserveCapacity(m_vector.capacity() * 4);
78
79 m_vector.uncheckedAppend(v);
80 m_buffer = m_vector.data();
81 }
82
83 } // namespace JSC