1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2003, 2007, 2008 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef ArgList_h
#define ArgList_h
#include "JSImmediate.h"
#include "Register.h"
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
namespace JSC {
class ArgList : Noncopyable {
private:
static const unsigned inlineCapacity = 8;
typedef Vector<Register, inlineCapacity> VectorType;
typedef HashSet<ArgList*> ListSet;
public:
typedef VectorType::iterator iterator;
typedef VectorType::const_iterator const_iterator;
// Constructor for a read-write list, to which you may append values.
// FIXME: Remove all clients of this API, then remove this API.
ArgList()
: m_markSet(0)
#ifndef NDEBUG
, m_isReadOnly(false)
#endif
{
m_buffer = m_vector.data();
m_size = 0;
}
// Constructor for a read-only list whose data has already been allocated elsewhere.
ArgList(Register* buffer, size_t size)
: m_buffer(buffer)
, m_size(size)
, m_markSet(0)
#ifndef NDEBUG
, m_isReadOnly(true)
#endif
{
}
void initialize(Register* buffer, size_t size)
{
ASSERT(!m_markSet);
ASSERT(isEmpty());
m_buffer = buffer;
m_size = size;
#ifndef NDEBUG
m_isReadOnly = true;
#endif
}
~ArgList()
{
if (m_markSet)
m_markSet->remove(this);
}
size_t size() const { return m_size; }
bool isEmpty() const { return !m_size; }
JSValuePtr at(ExecState* exec, size_t i) const
{
if (i < m_size)
return m_buffer[i].jsValue(exec);
return jsUndefined();
}
void clear()
{
m_vector.clear();
m_buffer = 0;
m_size = 0;
}
void append(JSValuePtr v)
{
ASSERT(!m_isReadOnly);
if (m_size < inlineCapacity) {
m_vector.uncheckedAppend(v);
++m_size;
} else {
// Putting this case all in one function measurably improves
// the performance of the fast "just append to inline buffer" case.
slowAppend(v);
++m_size;
}
}
void getSlice(int startIndex, ArgList& result) const;
iterator begin() { return m_buffer; }
iterator end() { return m_buffer + m_size; }
const_iterator begin() const { return m_buffer; }
const_iterator end() const { return m_buffer + m_size; }
static void markLists(ListSet&);
private:
void slowAppend(JSValuePtr);
Register* m_buffer;
size_t m_size;
VectorType m_vector;
ListSet* m_markSet;
#ifndef NDEBUG
bool m_isReadOnly;
#endif
private:
// Prohibits new / delete, which would break GC.
friend class JSGlobalData;
void* operator new(size_t size)
{
return fastMalloc(size);
}
void operator delete(void* p)
{
fastFree(p);
}
void* operator new[](size_t);
void operator delete[](void*);
void* operator new(size_t, void*);
void operator delete(void*, size_t);
};
} // namespace JSC
#endif // ArgList_h
|