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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
#ifdef __cplusplus
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
// extracted from stl_algobase.h
// full STL is not compatible with the ARM build
// a limited number of STL functions is used by webkit: swap, max, and min are
// included below for webkit compatibility
#ifdef __GLIBCPP_INTERNAL_ALGOBASE_H
#error "real STL defined"
#endif
#ifndef __ANDROID_ALGORITHM
#define __ANDROID_ALGORITHM
#ifndef __ANDROID_LIMITS
#include <limits>
#endif
#ifndef _CPP_UTILITY
#include <utility>
#endif
#include <SkScalar.h> // for SK_ScalarNaN
#ifdef PREFIX_FOR_WEBCORE
#include <SkTSearch.h>
namespace WebCore {
class InlineTextBox;
class RenderLayer;
}
#endif
#include <float.h>
#include <math.h>
#include <stdint.h>
#ifndef WCHAR_MAX
#define WCHAR_MAX 0xFFFF
#endif
namespace JSC {
class ProfileNode;
}
namespace WTF {
template <typename T> class RefPtr;
}
namespace std
{
template<typename _Tp>
inline void
swap(_Tp& __a, _Tp& __b)
{
_Tp __tmp = __a;
__a = __b;
__b = __tmp;
}
#undef min
#undef max
template<typename _Tp>
inline const _Tp&
min(const _Tp& __a, const _Tp& __b)
{
return __b < __a ? __b : __a;
}
template<typename _Tp>
inline const _Tp&
max(const _Tp& __a, const _Tp& __b)
{
return __a < __b ? __b : __a;
}
template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result)
{
for (size_t __n = __last - __first; __n > 0; --__n) {
*__result = *__first;
++__first;
++__result;
}
return __result;
}
template <class _ForwardIter, class _Tp>
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value) {
for ( ; __first != __last; ++__first)
*__first = __value;
}
#ifndef UINTPTR_MAX
#define UINTPTR_MAX UINT32_MAX
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (0xffffffff)
#endif
template <typename T>
struct numeric_limits {
/// Returns the minimum value for type T.
static inline T min (void) { return (T(0)); }
/// Returns the minimum value for type T.
static inline T max (void) { return (T(0)); }
static const bool is_signed = false; ///< True if the type is signed.
static const bool is_integer = false; ///< True if stores an exact value.
static const bool is_integral = false; ///< True if fixed size and cast-copyable.
};
template <typename T>
struct numeric_limits<T*> {
static inline T* min (void) { return (NULL); }
static inline T* max (void) { return (UINTPTR_MAX); }
static const bool is_signed = false;
static const bool is_integer = true;
static const bool is_integral = true;
};
#define _NUMERIC_LIMITS(type, minVal, maxVal, quietNaN, bSigned, bInteger, bIntegral) \
template <> \
struct numeric_limits<type> { \
static inline type infinity (void) { return (maxVal); } \
static inline type min (void) { return (minVal); } \
static inline type max (void) { return (maxVal); } \
static inline type quiet_NaN() { return (quietNaN); } \
static const bool is_signed = bSigned; \
static const bool is_integer = bInteger; \
static const bool is_integral = bIntegral; \
}
//--------------------------------------------------------------------------------------
// type min max NaN signed integer integral
//--------------------------------------------------------------------------------------
_NUMERIC_LIMITS (bool, false, true, 0, false, true, true);
_NUMERIC_LIMITS (char, SCHAR_MIN, SCHAR_MAX, 0, true, true, true);
_NUMERIC_LIMITS (int, INT_MIN, INT_MAX, 0, true, true, true);
_NUMERIC_LIMITS (short, SHRT_MIN, SHRT_MAX, 0, true, true, true);
_NUMERIC_LIMITS (long, LONG_MIN, LONG_MAX, 0, true, true, true);
#if HAVE_THREE_CHAR_TYPES
_NUMERIC_LIMITS (signed char, SCHAR_MIN, SCHAR_MAX, 0, true, true, true);
#endif
_NUMERIC_LIMITS (unsigned char, 0, UCHAR_MAX, 0, false, true, true);
_NUMERIC_LIMITS (unsigned int, 0, UINT_MAX, 0, false, true, true);
_NUMERIC_LIMITS (unsigned short,0, USHRT_MAX, 0, false, true, true);
_NUMERIC_LIMITS (unsigned long, 0, ULONG_MAX, 0, false, true, true);
_NUMERIC_LIMITS (wchar_t, 0, WCHAR_MAX, 0, false, true, true);
_NUMERIC_LIMITS (float, FLT_MIN, FLT_MAX, SK_ScalarNaN, true, false, true);
_NUMERIC_LIMITS (double, DBL_MIN, DBL_MAX, SK_ScalarNaN, true, false, true);
_NUMERIC_LIMITS (long double, LDBL_MIN, LDBL_MAX, SK_ScalarNaN, true, false, true);
#ifdef HAVE_LONG_LONG
_NUMERIC_LIMITS (long long, LLONG_MIN, LLONG_MAX, 0, true, true, true);
_NUMERIC_LIMITS (unsigned long long, 0, ULLONG_MAX, 0, false, true, true);
#endif
//--------------------------------------------------------------------------------------
typedef int ptrdiff_t;
typedef bool (* Comparator)(const void*, const void*);
extern void sort(const void** start, const void** end, Comparator comp);
#ifdef PREFIX_FOR_WEBCORE
typedef const void* sortType;
inline bool binary_search(const unsigned short* const base,
const unsigned short* const end,
short target)
{
return SkTSearch<unsigned short>(base, end - base, target, sizeof(unsigned short)) >= 0;
}
inline void sort (WebCore::InlineTextBox** start, WebCore::InlineTextBox**end,
bool (* comp)(const WebCore::InlineTextBox*, const WebCore::InlineTextBox*))
{
sort((const void**) start, (const void**) end, (Comparator) comp);
}
template<typename P> inline void stable_sort(P** start, P** end,
bool (* comp)(P*, P*))
{
sort((const void**) start, (const void**) end, (Comparator) comp);
}
template<typename P> inline void stable_sort(P** start, P** end,
bool (& comp)(const P*, const P*))
{
sort((const void**) start, (const void**) end, (Comparator) &comp);
}
template<typename P> void stable_sort(P* start, P* end, P* temp,
bool (& comp)(const P&, const P&)) {
size_t endlen = end - start;
size_t midlen = endlen / 2;
P* mid = start + midlen;
if (midlen > 1)
stable_sort(start, mid, temp, comp);
if (end - mid > 1)
stable_sort(mid, end, temp, comp);
memcpy(temp, start, midlen * sizeof(*start));
size_t i = 0;
size_t j = midlen;
size_t off = 0;
while (i < midlen && j < endlen) {
P* dst = (comp)(start[j], temp[i]) ? &start[j++] : &temp[i++];
memcpy(&start[off++], dst, sizeof(*start));
}
if (i < midlen)
memcpy(&start[off], &temp[i], (midlen - i) * sizeof(*start));
}
template<typename P> void stable_sort(P* start, P* end,
bool (& comp)(const P&, const P&)) {
if (end - start > 1) {
size_t count = (end - start) / 2;
P* temp = static_cast<P*>(malloc(count * sizeof(P)));
stable_sort(start, end, temp, comp);
free(temp);
}
}
template<typename P> void stable_sort(P* start, P* end,
bool (& comp)(P, P)) {
stable_sort(start, end, (bool (&)(const P&, const P&))(comp));
}
class ostream {
int this_class_intentionally_left_empty;
};
#endif
typedef bool (* ProfileComparator)(const WTF::RefPtr<JSC::ProfileNode>&,
const WTF::RefPtr<JSC::ProfileNode>&);
inline void sort(WTF::RefPtr<JSC::ProfileNode>* start,
WTF::RefPtr<JSC::ProfileNode>* end, ProfileComparator comp)
{
sort((const void**) start, (const void**) end, (Comparator) comp);
}
}
#endif
#endif // __cplusplus
|