]> git.saurik.com Git - apple/javascriptcore.git/blob - kjs/list.cpp
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / kjs / list.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 "list.h"
23
24 using std::min;
25
26 namespace KJS {
27
28 void List::getSlice(int startIndex, List& result) const
29 {
30 const_iterator start = min(begin() + startIndex, end());
31 result.m_vector.appendRange(start, end());
32 }
33
34 List::ListSet& List::markSet()
35 {
36 static ListSet staticMarkSet;
37 return staticMarkSet;
38 }
39
40 void List::markProtectedListsSlowCase()
41 {
42 ListSet::iterator end = markSet().end();
43 for (ListSet::iterator it = markSet().begin(); it != end; ++it) {
44 List* list = *it;
45
46 iterator end2 = list->end();
47 for (iterator it2 = list->begin(); it2 != end2; ++it2) {
48 JSValue* v = *it2;
49 if (!v->marked())
50 v->mark();
51 }
52 }
53 }
54
55 void List::expandAndAppend(JSValue* v)
56 {
57 ASSERT(m_vector.size() == m_vector.capacity());
58
59 // 4x growth would be excessive for a normal vector, but it's OK for Lists
60 // because they're short-lived.
61 m_vector.reserveCapacity(m_vector.capacity() * 4);
62
63 // As long as our size stays within our Vector's inline
64 // capacity, all our values are allocated on the stack, and
65 // therefore don't need explicit marking. Once our size exceeds
66 // our Vector's inline capacity, though, our values move to the
67 // heap, where they do need explicit marking.
68 if (!m_isInMarkSet) {
69 markSet().add(this);
70 m_isInMarkSet = true;
71 }
72
73 m_vector.uncheckedAppend(v);
74 }
75
76 } // namespace KJS