2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved.
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.
26 #include <wtf/HashSet.h>
27 #include <wtf/Noncopyable.h>
28 #include <wtf/Vector.h>
34 class MarkedArgumentBuffer
: public Noncopyable
{
36 static const unsigned inlineCapacity
= 8;
37 typedef Vector
<Register
, inlineCapacity
> VectorType
;
38 typedef HashSet
<MarkedArgumentBuffer
*> ListSet
;
41 typedef VectorType::iterator iterator
;
42 typedef VectorType::const_iterator const_iterator
;
44 // Constructor for a read-write list, to which you may append values.
45 // FIXME: Remove all clients of this API, then remove this API.
46 MarkedArgumentBuffer()
47 : m_isUsingInlineBuffer(true)
53 m_buffer
= m_vector
.data();
57 // Constructor for a read-only list whose data has already been allocated elsewhere.
58 MarkedArgumentBuffer(Register
* buffer
, size_t size
)
61 , m_isUsingInlineBuffer(true)
69 void initialize(Register
* buffer
, size_t size
)
81 ~MarkedArgumentBuffer()
84 m_markSet
->remove(this);
87 size_t size() const { return m_size
; }
88 bool isEmpty() const { return !m_size
; }
90 JSValue
at(size_t i
) const
93 return m_buffer
[i
].jsValue();
104 void append(JSValue v
)
106 ASSERT(!m_isReadOnly
);
108 #if ENABLE(JSC_ZOMBIES)
109 ASSERT(!v
.isZombie());
112 if (m_isUsingInlineBuffer
&& m_size
< inlineCapacity
) {
113 m_vector
.uncheckedAppend(v
);
116 // Putting this case all in one function measurably improves
117 // the performance of the fast "just append to inline buffer" case.
120 m_isUsingInlineBuffer
= false;
128 m_vector
.removeLast();
134 return m_buffer
[m_size
- 1].jsValue();
137 iterator
begin() { return m_buffer
; }
138 iterator
end() { return m_buffer
+ m_size
; }
140 const_iterator
begin() const { return m_buffer
; }
141 const_iterator
end() const { return m_buffer
+ m_size
; }
143 static void markLists(MarkStack
&, ListSet
&);
146 void slowAppend(JSValue
);
150 bool m_isUsingInlineBuffer
;
159 // Prohibits new / delete, which would break GC.
160 friend class JSGlobalData
;
162 void* operator new(size_t size
)
164 return fastMalloc(size
);
166 void operator delete(void* p
)
171 void* operator new[](size_t);
172 void operator delete[](void*);
174 void* operator new(size_t, void*);
175 void operator delete(void*, size_t);
181 typedef JSValue
* iterator
;
182 typedef const JSValue
* const_iterator
;
190 ArgList(JSValue
* args
, unsigned argCount
)
192 , m_argCount(argCount
)
194 #if ENABLE(JSC_ZOMBIES)
195 for (size_t i
= 0; i
< argCount
; i
++)
196 ASSERT(!m_args
[i
].isZombie());
200 ArgList(Register
* args
, int argCount
)
201 : m_args(reinterpret_cast<JSValue
*>(args
))
202 , m_argCount(argCount
)
204 ASSERT(argCount
>= 0);
207 ArgList(const MarkedArgumentBuffer
& args
)
208 : m_args(reinterpret_cast<JSValue
*>(const_cast<Register
*>(args
.begin())))
209 , m_argCount(args
.size())
213 JSValue
at(size_t idx
) const
215 if (idx
< m_argCount
)
217 return jsUndefined();
220 bool isEmpty() const { return !m_argCount
; }
222 size_t size() const { return m_argCount
; }
224 iterator
begin() { return m_args
; }
225 iterator
end() { return m_args
+ m_argCount
; }
227 const_iterator
begin() const { return m_args
; }
228 const_iterator
end() const { return m_args
+ m_argCount
; }
230 void getSlice(int startIndex
, ArgList
& result
) const;