2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007 Apple Computer, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include <kjs/value.h>
26 #include <wtf/HashSet.h>
27 #include <wtf/Noncopyable.h>
28 #include <wtf/Vector.h>
35 class List
: Noncopyable
{
37 typedef Vector
<JSValue
*, 8> VectorType
;
38 typedef HashSet
<List
*> ListSet
;
41 typedef VectorType::iterator iterator
;
42 typedef VectorType::const_iterator const_iterator
;
45 : m_isInMarkSet(false)
52 markSet().remove(this);
55 size_t size() const { return m_vector
.size(); }
56 bool isEmpty() const { return m_vector
.isEmpty(); }
58 JSValue
* at(size_t i
) const
60 if (i
< m_vector
.size())
61 return m_vector
.at(i
);
65 JSValue
* operator[](int i
) const { return at(i
); }
67 void clear() { m_vector
.clear(); }
69 void append(JSValue
* v
)
71 if (m_vector
.size() < m_vector
.capacity())
72 m_vector
.uncheckedAppend(v
);
74 // Putting the slow "expand and append" case all in one
75 // function measurably improves the performance of the fast
76 // "just append" case.
80 void getSlice(int startIndex
, List
& result
) const;
82 iterator
begin() { return m_vector
.begin(); }
83 iterator
end() { return m_vector
.end(); }
85 const_iterator
begin() const { return m_vector
.begin(); }
86 const_iterator
end() const { return m_vector
.end(); }
88 static void markProtectedLists()
90 if (!markSet().size())
92 markProtectedListsSlowCase();
96 static ListSet
& markSet();
97 static void markProtectedListsSlowCase();
99 void expandAndAppend(JSValue
*);
105 // Prohibits new / delete, which would break GC.
106 void* operator new(size_t);
107 void operator delete(void*);
109 void* operator new[](size_t);
110 void operator delete[](void*);
112 void* operator new(size_t, void*);
113 void operator delete(void*, size_t);