]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ArgList.cpp
JavaScriptCore-903.5.tar.gz
[apple/javascriptcore.git] / runtime / ArgList.cpp
CommitLineData
b37bf2e1 1/*
f9bf01c6 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
b37bf2e1
A
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"
9dae56ea
A
22#include "ArgList.h"
23
24#include "JSValue.h"
25#include "JSCell.h"
14957cd0
A
26#include "JSObject.h"
27#include "ScopeChain.h"
b37bf2e1
A
28
29using std::min;
30
9dae56ea 31namespace JSC {
b37bf2e1 32
9dae56ea 33void ArgList::getSlice(int startIndex, ArgList& result) const
b37bf2e1 34{
ba379fdc
A
35 if (startIndex <= 0 || static_cast<unsigned>(startIndex) >= m_argCount) {
36 result = ArgList(m_args, 0);
37 return;
38 }
39 result = ArgList(m_args + startIndex, m_argCount - startIndex);
b37bf2e1
A
40}
41
14957cd0 42void MarkedArgumentBuffer::markLists(HeapRootVisitor& heapRootMarker, ListSet& markSet)
b37bf2e1 43{
9dae56ea
A
44 ListSet::iterator end = markSet.end();
45 for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
ba379fdc 46 MarkedArgumentBuffer* list = *it;
14957cd0 47 heapRootMarker.mark(reinterpret_cast<JSValue*>(list->m_buffer), list->m_size);
b37bf2e1
A
48 }
49}
50
ba379fdc 51void MarkedArgumentBuffer::slowAppend(JSValue v)
b37bf2e1 52{
b37bf2e1
A
53 // As long as our size stays within our Vector's inline
54 // capacity, all our values are allocated on the stack, and
55 // therefore don't need explicit marking. Once our size exceeds
56 // our Vector's inline capacity, though, our values move to the
57 // heap, where they do need explicit marking.
9dae56ea 58 if (!m_markSet) {
14957cd0
A
59 // FIXME: Even if v is not a JSCell*, if previous values in the buffer
60 // are, then they won't be marked!
9dae56ea
A
61 if (Heap* heap = Heap::heap(v)) {
62 ListSet& markSet = heap->markListSet();
63 markSet.add(this);
64 m_markSet = &markSet;
65 }
66 }
67
68 if (m_vector.size() < m_vector.capacity()) {
69 m_vector.uncheckedAppend(v);
70 return;
b37bf2e1
A
71 }
72
9dae56ea
A
73 // 4x growth would be excessive for a normal vector, but it's OK for Lists
74 // because they're short-lived.
75 m_vector.reserveCapacity(m_vector.capacity() * 4);
76
b37bf2e1 77 m_vector.uncheckedAppend(v);
9dae56ea 78 m_buffer = m_vector.data();
b37bf2e1
A
79}
80
9dae56ea 81} // namespace JSC