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
|
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
|
-
+
-
-
-
-
+
+
+
+
-
-
+
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <stdarg.h>
#import "OFAdjacentArray.h"
#import "OFAdjacentSubarray.h"
#import "OFData.h"
#import "OFMutableAdjacentArray.h"
#import "OFConcreteArray.h"
#import "OFConcreteMutableArray.h"
#import "OFConcreteSubarray.h"
#import "OFData.h"
#import "OFString.h"
#import "OFXMLElement.h"
#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"
@implementation OFAdjacentArray
@implementation OFConcreteArray
- (instancetype)init
{
self = [super init];
@try {
_array = [[OFMutableData alloc] initWithItemSize: sizeof(id)];
} @catch (id e) {
|
| ︙ | | |
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
|
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
|
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
}
return self;
}
- (instancetype)initWithObjects: (id const *)objects count: (size_t)count
{
self = [self init];
self = [super init];
@try {
bool ok = true;
for (size_t i = 0; i < count; i++) {
if (objects[i] == nil)
ok = false;
[objects[i] retain];
}
if (!ok)
@throw [OFInvalidArgumentException exception];
_array = [[OFMutableData alloc] initWithItemSize: sizeof(id)
capacity: count];
[_array addItems: objects count: count];
} @catch (id e) {
for (size_t i = 0; i < count; i++)
[objects[i] release];
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
self = [self init];
@try {
void *pool = objc_autoreleasePoolPush();
if ((![element.name isEqual: @"OFArray"] &&
![element.name isEqual: @"OFMutableArray"]) ||
![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
for (OFXMLElement *child in
[element elementsForNamespace: OFSerializationNS]) {
void *pool2 = objc_autoreleasePoolPush();
id object;
object = child.objectByDeserializing;
[_array addItem: &object];
[object retain];
objc_autoreleasePoolPop(pool2);
}
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (size_t)count
{
return _array.count;
}
|
| ︙ | | |
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
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
|
+
-
+
-
-
+
+
|
@throw [OFOutOfRangeException exception];
if ([self isKindOfClass: [OFMutableArray class]])
return [OFArray
arrayWithObjects: (id *)_array.items + range.location
count: range.length];
return [[[OFConcreteSubarray alloc] initWithArray: self
return [OFAdjacentSubarray arrayWithArray: self range: range];
range: range] autorelease];
}
- (bool)isEqual: (id)object
{
OFArray *otherArray;
id const *objects, *otherObjects;
size_t count;
if (object == self)
return true;
if (![object isKindOfClass: [OFAdjacentArray class]] &&
![object isKindOfClass: [OFMutableAdjacentArray class]])
if (![object isKindOfClass: [OFConcreteArray class]] &&
![object isKindOfClass: [OFConcreteMutableArray class]])
return [super isEqual: object];
otherArray = object;
count = _array.count;
if (count != otherArray.count)
|
| ︙ | | |
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
+
-
+
|
return hash;
}
- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
objects: (id *)objects
count: (int)count_
{
static unsigned long dummyMutations;
size_t count = _array.count;
if (count > INT_MAX)
/*
* Use the implementation from OFArray, which is slower, but can
* enumerate in chunks.
*/
return [super countByEnumeratingWithState: state
objects: objects
count: count_];
if (state->state >= count)
return 0;
state->state = (unsigned long)count;
state->itemsPtr = (id *)_array.items;
state->mutationsPtr = (unsigned long *)self;
state->mutationsPtr = &dummyMutations;
return (int)count;
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block
{
|
| ︙ | | |