blob: 9b9a8f01e575f4b850bfac2409efb8e563c7e134 [file] [log] [blame]
kocienda66a6d362001-08-24 14:24:45 +00001/*
darinb7bf3972007-03-19 23:50:43 +00002 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
kocienda66a6d362001-08-24 14:24:45 +00003 *
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
mjscdff33b2006-01-23 21:41:36 +000016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
ggaren07d4ce62005-07-14 18:27:04 +000017 * Boston, MA 02110-1301, USA.
mjs6f821c82002-03-22 00:31:57 +000018 *
kocienda66a6d362001-08-24 14:24:45 +000019 */
20
mjsb64c50a2005-10-03 21:13:12 +000021#include "config.h"
darinff399e02002-11-23 07:49:05 +000022#include "list.h"
mjs6f821c82002-03-22 00:31:57 +000023
mrowe@apple.comcf617a52007-11-05 23:05:03 +000024using std::min;
25
darinff399e02002-11-23 07:49:05 +000026namespace KJS {
27
ggaren879ab752007-11-05 21:27:15 +000028void List::getSlice(int startIndex, List& result) const
darinff399e02002-11-23 07:49:05 +000029{
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000030 ASSERT(!result.m_isReadOnly);
31
ggaren879ab752007-11-05 21:27:15 +000032 const_iterator start = min(begin() + startIndex, end());
33 result.m_vector.appendRange(start, end());
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000034 result.m_size = result.m_vector.size();
andersca@apple.comcf11a692008-05-23 23:44:40 +000035 result.m_bufferSlot = result.m_vector.dataSlot();
mjs0e6b4f02002-11-26 23:52:00 +000036}
37
ap@webkit.orga1669f32008-06-12 14:34:38 +000038void List::markLists(ListSet& markSet)
ggaren879ab752007-11-05 21:27:15 +000039{
ap@webkit.orga1669f32008-06-12 14:34:38 +000040 ListSet::iterator end = markSet.end();
41 for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
ggaren879ab752007-11-05 21:27:15 +000042 List* list = *it;
43
44 iterator end2 = list->end();
mrowe@apple.com397036a2007-11-28 13:12:03 +000045 for (iterator it2 = list->begin(); it2 != end2; ++it2) {
46 JSValue* v = *it2;
47 if (!v->marked())
48 v->mark();
49 }
ggaren879ab752007-11-05 21:27:15 +000050 }
51}
52
ap@webkit.orga1669f32008-06-12 14:34:38 +000053void List::slowAppend(JSValue* v)
ggaren879ab752007-11-05 21:27:15 +000054{
ggaren879ab752007-11-05 21:27:15 +000055 // 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.
ap@webkit.orga1669f32008-06-12 14:34:38 +000060 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 (!JSImmediate::isImmediate(v)) { // Will be: if (Heap* heap = Heap::heap(v))
64 ListSet& markSet = Collector::markListSet();
65 markSet.add(this);
66 m_markSet = &markSet;
67 }
ggaren879ab752007-11-05 21:27:15 +000068 }
69
ap@webkit.orga1669f32008-06-12 14:34:38 +000070 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
ggaren879ab752007-11-05 21:27:15 +000079 m_vector.uncheckedAppend(v);
ap@webkit.orga1669f32008-06-12 14:34:38 +000080 m_bufferSlot = m_vector.dataSlot();
darinf7fc08d2002-11-20 08:53:04 +000081}
darin20330f72002-11-20 22:59:04 +000082
83} // namespace KJS