kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 1 | /* |
darin | b7bf397 | 2007-03-19 23:50:43 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 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 |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 17 | * Boston, MA 02110-1301, USA. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 18 | * |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 21 | #include "config.h" |
darin | ff399e0 | 2002-11-23 07:49:05 +0000 | [diff] [blame] | 22 | #include "list.h" |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 23 | |
mrowe@apple.com | cf617a5 | 2007-11-05 23:05:03 +0000 | [diff] [blame] | 24 | using std::min; |
| 25 | |
darin | ff399e0 | 2002-11-23 07:49:05 +0000 | [diff] [blame] | 26 | namespace KJS { |
| 27 | |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 28 | void List::getSlice(int startIndex, List& result) const |
darin | ff399e0 | 2002-11-23 07:49:05 +0000 | [diff] [blame] | 29 | { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 30 | ASSERT(!result.m_isReadOnly); |
| 31 | |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 32 | const_iterator start = min(begin() + startIndex, end()); |
| 33 | result.m_vector.appendRange(start, end()); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 34 | result.m_size = result.m_vector.size(); |
andersca@apple.com | cf11a69 | 2008-05-23 23:44:40 +0000 | [diff] [blame] | 35 | result.m_bufferSlot = result.m_vector.dataSlot(); |
mjs | 0e6b4f0 | 2002-11-26 23:52:00 +0000 | [diff] [blame] | 36 | } |
| 37 | |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 38 | void List::markLists(ListSet& markSet) |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 39 | { |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 40 | ListSet::iterator end = markSet.end(); |
| 41 | for (ListSet::iterator it = markSet.begin(); it != end; ++it) { |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 42 | List* list = *it; |
| 43 | |
| 44 | iterator end2 = list->end(); |
mrowe@apple.com | 397036a | 2007-11-28 13:12:03 +0000 | [diff] [blame] | 45 | for (iterator it2 = list->begin(); it2 != end2; ++it2) { |
| 46 | JSValue* v = *it2; |
| 47 | if (!v->marked()) |
| 48 | v->mark(); |
| 49 | } |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 53 | void List::slowAppend(JSValue* v) |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 54 | { |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 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. |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 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 (!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 | } |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 68 | } |
| 69 | |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 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 | |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 79 | m_vector.uncheckedAppend(v); |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame^] | 80 | m_bufferSlot = m_vector.dataSlot(); |
darin | f7fc08d | 2002-11-20 08:53:04 +0000 | [diff] [blame] | 81 | } |
darin | 20330f7 | 2002-11-20 22:59:04 +0000 | [diff] [blame] | 82 | |
| 83 | } // namespace KJS |