︙ | | |
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
|
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
|
-
+
-
-
+
-
-
+
-
+
-
+
-
|
return self;
}
- (void)addObject: (id)object
{
if (object == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
[_array addItem: &object];
[object retain];
_mutations++;
}
- (void)insertObject: (id)object
atIndex: (size_t)index
{
if (object == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
@try {
[_array insertItem: &object
atIndex: index];
} @catch (OFOutOfRangeException *e) {
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
@throw [OFOutOfRangeException exception];
}
[object retain];
_mutations++;
}
- (void)insertObjectsFromArray: (OFArray*)array
atIndex: (size_t)index
{
id *objects = [array objects];
size_t i, count = [array count];
@try {
[_array insertItems: objects
atIndex: index
count: count];
} @catch (OFOutOfRangeException *e) {
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
@throw [OFOutOfRangeException exception];
}
for (i = 0; i < count; i++)
[objects[i] retain];
_mutations++;
}
- (void)replaceObject: (id)oldObject
withObject: (id)newObject
{
id *objects;
size_t i, count;
if (oldObject == nil || newObject == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
objects = [_array items];
count = [_array count];
for (i = 0; i < count; i++) {
if ([objects[i] isEqual: oldObject]) {
[newObject retain];
|
︙ | | |
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
|
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
|
-
+
-
-
+
-
+
-
|
- (void)replaceObjectAtIndex: (size_t)index
withObject: (id)object
{
id *objects;
id oldObject;
if (object == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
objects = [_array items];
if (index >= [_array count])
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
@throw [OFOutOfRangeException exception];
oldObject = objects[index];
objects[index] = [object retain];
[oldObject release];
}
- (void)replaceObjectIdenticalTo: (id)oldObject
withObject: (id)newObject
{
id *objects;
size_t i, count;
if (oldObject == nil || newObject == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
objects = [_array items];
count = [_array count];
for (i = 0; i < count; i++) {
if (objects[i] == oldObject) {
[newObject retain];
|
︙ | | |
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
-
+
-
|
- (void)removeObject: (id)object
{
id *objects;
size_t i, count;
if (object == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
objects = [_array items];
count = [_array count];
for (i = 0; i < count; i++) {
if ([objects[i] isEqual: object]) {
object = objects[i];
|
︙ | | |
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
-
+
-
|
- (void)removeObjectIdenticalTo: (id)object
{
id *objects;
size_t i, count;
if (object == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]];
objects = [_array items];
count = [_array count];
for (i = 0; i < count; i++) {
if (objects[i] == object) {
[_array removeItemAtIndex: i];
|
︙ | | |
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
-
+
|
- (void)removeObjectsInRange: (of_range_t)range
{
id *objects = [_array items], *copy;
size_t i, count = [_array count];
if (range.length > SIZE_MAX - range.location ||
range.length > count - range.location)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
@throw [OFOutOfRangeException exception];
copy = [self allocMemoryWithSize: sizeof(*copy)
count: range.length];
memcpy(copy, objects + range.location, range.length * sizeof(id));
@try {
[_array removeItemsInRange: range];
|
︙ | | |
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
-
+
|
withObjectAtIndex: (size_t)index2
{
id *objects = [_array items];
size_t count = [_array count];
id tmp;
if (index1 >= count || index2 >= count)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
@throw [OFOutOfRangeException exception];
tmp = objects[index1];
objects[index1] = objects[index2];
objects[index2] = tmp;
}
- (void)reverse
|
︙ | | |
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
-
-
+
-
-
+
-
+
-
-
|
size_t i, count = [_array count];
bool stop = false;
unsigned long mutations = _mutations;
for (i = 0; i < count && !stop; i++) {
if (_mutations != mutations)
@throw [OFEnumerationMutationException
exceptionWithClass: [self class]
object: self];
exceptionWithObject: self];
block(objects[i], i, &stop);
}
}
- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block
{
id *objects = [_array items];
size_t i, count = [_array count];
unsigned long mutations = _mutations;
for (i = 0; i < count; i++) {
id new;
if (_mutations != mutations)
@throw [OFEnumerationMutationException
exceptionWithClass: [self class]
object: self];
exceptionWithObject: self];
new = block(objects[i], i);
if (new == nil)
@throw [OFInvalidArgumentException
@throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
if (new != objects[i]) {
[objects[i] release];
objects[i] = [new retain];
}
}
}
|
︙ | | |