2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008 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 "JSImmediate.h"
28 #include <wtf/HashSet.h>
29 #include <wtf/Noncopyable.h>
30 #include <wtf/Vector.h>
34 class ArgList
: Noncopyable
{
36 static const unsigned inlineCapacity
= 8;
37 typedef Vector
<Register
, inlineCapacity
> VectorType
;
38 typedef HashSet
<ArgList
*> 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.
52 m_buffer
= m_vector
.data();
56 // Constructor for a read-only list whose data has already been allocated elsewhere.
57 ArgList(Register
* buffer
, size_t size
)
67 void initialize(Register
* buffer
, size_t size
)
82 m_markSet
->remove(this);
85 size_t size() const { return m_size
; }
86 bool isEmpty() const { return !m_size
; }
88 JSValuePtr
at(ExecState
* exec
, size_t i
) const
91 return m_buffer
[i
].jsValue(exec
);
102 void append(JSValuePtr v
)
104 ASSERT(!m_isReadOnly
);
106 if (m_size
< inlineCapacity
) {
107 m_vector
.uncheckedAppend(v
);
110 // Putting this case all in one function measurably improves
111 // the performance of the fast "just append to inline buffer" case.
117 void getSlice(int startIndex
, ArgList
& result
) const;
119 iterator
begin() { return m_buffer
; }
120 iterator
end() { return m_buffer
+ m_size
; }
122 const_iterator
begin() const { return m_buffer
; }
123 const_iterator
end() const { return m_buffer
+ m_size
; }
125 static void markLists(ListSet
&);
128 void slowAppend(JSValuePtr
);
140 // Prohibits new / delete, which would break GC.
141 friend class JSGlobalData
;
143 void* operator new(size_t size
)
145 return fastMalloc(size
);
147 void operator delete(void* p
)
152 void* operator new[](size_t);
153 void operator delete[](void*);
155 void* operator new(size_t, void*);
156 void operator delete(void*, size_t);