• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
getSlice(int startIndex,ArgList & result) const31 void ArgList::getSlice(int startIndex, ArgList& result) const
32 {
33     ASSERT(!result.m_isReadOnly);
34 
35     const_iterator start = min(begin() + startIndex, end());
36     result.m_vector.appendRange(start, end());
37     result.m_size = result.m_vector.size();
38     result.m_buffer = result.m_vector.data();
39 }
40 
markLists(ListSet & markSet)41 void ArgList::markLists(ListSet& markSet)
42 {
43     ListSet::iterator end = markSet.end();
44     for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
45         ArgList* list = *it;
46 
47         iterator end2 = list->end();
48         for (iterator it2 = list->begin(); it2 != end2; ++it2)
49             if (!(*it2).marked())
50                 (*it2).mark();
51     }
52 }
53 
slowAppend(JSValuePtr v)54 void ArgList::slowAppend(JSValuePtr v)
55 {
56     // As long as our size stays within our Vector's inline
57     // capacity, all our values are allocated on the stack, and
58     // therefore don't need explicit marking. Once our size exceeds
59     // our Vector's inline capacity, though, our values move to the
60     // heap, where they do need explicit marking.
61     if (!m_markSet) {
62         // We can only register for explicit marking once we know which heap
63         // is the current one, i.e., when a non-immediate value is appended.
64         if (Heap* heap = Heap::heap(v)) {
65             ListSet& markSet = heap->markListSet();
66             markSet.add(this);
67             m_markSet = &markSet;
68         }
69     }
70 
71     if (m_vector.size() < m_vector.capacity()) {
72         m_vector.uncheckedAppend(v);
73         return;
74     }
75 
76     // 4x growth would be excessive for a normal vector, but it's OK for Lists
77     // because they're short-lived.
78     m_vector.reserveCapacity(m_vector.capacity() * 4);
79 
80     m_vector.uncheckedAppend(v);
81     m_buffer = m_vector.data();
82 }
83 
84 } // namespace JSC
85