ObjFW  Diff

Differences From Artifact [e02a8ee9e6]:

To Artifact [a923c5af53]:


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
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







-
+



-
+

-
-
+
+









-
+





-
-
+
+






-
+



-
+

-
-
+
+








-
+



-
-
+
+













-
+



-
+








	mutations++;
}

- (void)replaceObject: (id)oldObject
	   withObject: (id)newObject
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([cArray[i] isEqual: oldObject]) {
		if ([objects[i] isEqual: oldObject]) {
			[newObject retain];
			[cArray[i] release];
			cArray[i] = newObject;
			[objects[i] release];
			objects[i] = newObject;

			return;
		}
	}
}

- (void)replaceObjectAtIndex: (size_t)index
		  withObject: (id)object
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	id oldObject;

	if (index >= [array count])
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	oldObject = cArray[index];
	cArray[index] = [object retain];
	oldObject = objects[index];
	objects[index] = [object retain];
	[oldObject release];
}

- (void)replaceObjectIdenticalTo: (id)oldObject
		      withObject: (id)newObject
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (cArray[i] == oldObject) {
		if (objects[i] == oldObject) {
			[newObject retain];
			[cArray[i] release];
			cArray[i] = newObject;
			[objects[i] release];
			objects[i] = newObject;

			return;
		}
	}
}

- (void)removeObject: (id)object
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([cArray[i] isEqual: object]) {
			object = cArray[i];
		if ([objects[i] isEqual: object]) {
			object = objects[i];

			[array removeItemAtIndex: i];
			mutations++;

			[object release];

			return;
		}
	}
}

- (void)removeObjectIdenticalTo: (id)object
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (cArray[i] == object) {
		if (objects[i] == object) {
			[array removeItemAtIndex: i];
			mutations++;

			[object release];

			return;
		}
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
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







-
+







-
+














-
+



-
+






-
+







-
+







	[object release];

	mutations++;
}

- (void)removeNObjects: (size_t)nObjects
{
	id *cArray = [array cArray], *copy;
	id *objects = [array cArray], *copy;
	size_t i, count = [array count];

	if (nObjects > count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	copy = [self allocMemoryForNItems: nObjects
				   ofSize: sizeof(id)];
	memcpy(copy, cArray + (count - nObjects), nObjects * sizeof(id));
	memcpy(copy, objects + (count - nObjects), nObjects * sizeof(id));

	@try {
		[array removeNItems: nObjects];
		mutations++;

		for (i = 0; i < nObjects; i++)
			[copy[i] release];
	} @finally {
		[self freeMemory: copy];
	}
}

- (void)removeAllObjects
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++)
		[cArray[i] release];
		[objects[i] release];

	[array removeAllItems];
}

- (void)removeObjectsInRange: (of_range_t)range
{
	id *cArray = [array cArray], *copy;
	id *objects = [array cArray], *copy;
	size_t i, count = [array count];

	if (range.length > count - range.start)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	copy = [self allocMemoryForNItems: range.length
				   ofSize: sizeof(id)];
	memcpy(copy, cArray + range.start, range.length * sizeof(id));
	memcpy(copy, objects + range.start, range.length * sizeof(id));

	@try {
		[array removeNItems: range.length
			    atIndex: range.start];
		mutations++;

		for (i = 0; i < range.length; i++)
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
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







-
+






-
-
-
+
+
+




-
+






-
-
-
+
+
+








	mutations++;
}

- (void)swapObjectAtIndex: (size_t)index1
	withObjectAtIndex: (size_t)index2
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t count = [array count];
	id tmp;

	if (index1 >= count || index2 >= count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	tmp = cArray[index1];
	cArray[index1] = cArray[index2];
	cArray[index2] = tmp;
	tmp = objects[index1];
	objects[index1] = objects[index2];
	objects[index2] = tmp;
}

- (void)reverse
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, j, count = [array count];

	if (count == 0 || count == 1)
		return;

	for (i = 0, j = count - 1; i < j; i++, j--) {
		id tmp = cArray[i];
		cArray[i] = cArray[j];
		cArray[j] = tmp;
		id tmp = objects[i];
		objects[i] = objects[j];
		objects[j] = tmp;
	}
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{
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

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
317
318
319
320
321
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
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
317
318
319
320
321







-
+










-
+





-
+












-
+







-
-
+
+









	    initWithArray: self
	     mutationsPtr: &mutations] autorelease];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];
	BOOL stop = NO;
	unsigned long mutations2 = mutations;

	for (i = 0; i < count && !stop; i++) {
		if (mutations != mutations2)
			@throw [OFEnumerationMutationException
			    exceptionWithClass: isa
					object: self];

		block(cArray[i], i, &stop);
		block(objects[i], i, &stop);
	}
}

- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block
{
	id *cArray = [array cArray];
	id *objects = [array cArray];
	size_t i, count = [array count];
	BOOL stop = NO;
	unsigned long mutations2 = mutations;

	for (i = 0; i < count && !stop; i++) {
		id newObject;

		if (mutations != mutations2)
			@throw [OFEnumerationMutationException
			    exceptionWithClass: isa
					object: self];

		newObject = block(cArray[i], i, &stop);
		newObject = block(objects[i], i, &stop);

		if (newObject == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		[newObject retain];
		[cArray[i] release];
		cArray[i] = newObject;
		[objects[i] release];
		objects[i] = newObject;
	}
}
#endif

- (void)makeImmutable
{
	isa = [OFArray_adjacent class];
}
@end