2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008, 2009 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.
27 #include <wtf/HashSet.h>
28 #include <wtf/Noncopyable.h>
29 #include <wtf/Vector.h>
33 class MarkedArgumentBuffer
: Noncopyable
{
35 static const unsigned inlineCapacity
= 8;
36 typedef Vector
<Register
, inlineCapacity
> VectorType
;
37 typedef HashSet
<MarkedArgumentBuffer
*> ListSet
;
40 typedef VectorType::iterator iterator
;
41 typedef VectorType::const_iterator const_iterator
;
43 // Constructor for a read-write list, to which you may append values.
44 // FIXME: Remove all clients of this API, then remove this API.
45 MarkedArgumentBuffer()
46 : m_isUsingInlineBuffer(true)
52 m_buffer
= m_vector
.data();
56 // Constructor for a read-only list whose data has already been allocated elsewhere.
57 MarkedArgumentBuffer(Register
* buffer
, size_t size
)
60 , m_isUsingInlineBuffer(true)
68 void initialize(Register
* buffer
, size_t size
)
80 ~MarkedArgumentBuffer()
83 m_markSet
->remove(this);
86 size_t size() const { return m_size
; }
87 bool isEmpty() const { return !m_size
; }
89 JSValue
at(size_t i
) const
92 return m_buffer
[i
].jsValue();
103 void append(JSValue v
)
105 ASSERT(!m_isReadOnly
);
107 if (m_isUsingInlineBuffer
&& m_size
< inlineCapacity
) {
108 m_vector
.uncheckedAppend(v
);
111 // Putting this case all in one function measurably improves
112 // the performance of the fast "just append to inline buffer" case.
115 m_isUsingInlineBuffer
= false;
123 m_vector
.removeLast();
129 return m_buffer
[m_size
- 1].jsValue();
132 iterator
begin() { return m_buffer
; }
133 iterator
end() { return m_buffer
+ m_size
; }
135 const_iterator
begin() const { return m_buffer
; }
136 const_iterator
end() const { return m_buffer
+ m_size
; }
138 static void markLists(ListSet
&);
141 void slowAppend(JSValue
);
145 bool m_isUsingInlineBuffer
;
154 // Prohibits new / delete, which would break GC.
155 friend class JSGlobalData
;
157 void* operator new(size_t size
)
159 return fastMalloc(size
);
161 void operator delete(void* p
)
166 void* operator new[](size_t);
167 void operator delete[](void*);
169 void* operator new(size_t, void*);
170 void operator delete(void*, size_t);
176 typedef JSValue
* iterator
;
177 typedef const JSValue
* const_iterator
;
185 ArgList(JSValue
* args
, unsigned argCount
)
187 , m_argCount(argCount
)
191 ArgList(Register
* args
, int argCount
)
192 : m_args(reinterpret_cast<JSValue
*>(args
))
193 , m_argCount(argCount
)
195 ASSERT(argCount
>= 0);
198 ArgList(const MarkedArgumentBuffer
& args
)
199 : m_args(reinterpret_cast<JSValue
*>(const_cast<Register
*>(args
.begin())))
200 , m_argCount(args
.size())
204 JSValue
at(size_t idx
) const
206 if (idx
< m_argCount
)
208 return jsUndefined();
211 bool isEmpty() const { return !m_argCount
; }
213 size_t size() const { return m_argCount
; }
215 iterator
begin() { return m_args
; }
216 iterator
end() { return m_args
+ m_argCount
; }
218 const_iterator
begin() const { return m_args
; }
219 const_iterator
end() const { return m_args
+ m_argCount
; }
221 void getSlice(int startIndex
, ArgList
& result
) const;