ObjFW  Diff

Differences From Artifact [66616ef22a]:

To Artifact [b1e29fe508]:


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







-
+


















-
+





-
+



















-


-
+












-
-
-
+








	return self;
}

- initWithArray: (OFArray*)array
{
	id const *objects;
	size_t i, count;
	size_t count;

	self = [super init];

	if (array == nil)
		return self;

	@try {
		objects = [array objects];
		count = [array count];

		_array = [[OFDataArray alloc] initWithItemSize: sizeof(id)
						      capacity: count];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	@try {
		for (i = 0; i < count; i++)
		for (size_t i = 0; i < count; i++)
			[objects[i] retain];

		[_array addItems: objects
			   count: count];
	} @catch (id e) {
		for (i = 0; i < count; i++)
		for (size_t i = 0; i < count; i++)
			[objects[i] release];

		/* Prevent double-release of objects */
		[_array release];
		_array = nil;

		[self release];
		@throw e;
	}

	return self;
}

- initWithObjects: (id const*)objects
	    count: (size_t)count
{
	self = [self init];

	@try {
		size_t i;
		bool ok = true;

		for (i = 0; i < count; i++) {
		for (size_t i = 0; i < count; i++) {
			if (objects[i] == nil)
				ok = false;

			[objects[i] retain];
		}

		if (!ok)
			@throw [OFInvalidArgumentException exception];

		[_array addItems: objects
			   count: count];
	} @catch (id e) {
		size_t i;

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

		[self release];
		@throw e;
	}

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







-
+





-
+






-
+







-
+









-
+







-
+







	return *((id*)[_array itemAtIndex: index]);
}

- (void)getObjects: (id*)buffer
	   inRange: (of_range_t)range
{
	id *objects = [_array items];
	size_t i, count = [_array count];
	size_t count = [_array count];

	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > count)
		@throw [OFOutOfRangeException exception];

	for (i = 0; i < range.length; i++)
	for (size_t i = 0; i < range.length; i++)
		buffer[i] = objects[range.location + i];
}

- (size_t)indexOfObject: (id)object
{
	id *objects;
	size_t i, count;
	size_t count;

	if (object == nil)
		return OF_NOT_FOUND;

	objects = [_array items];
	count = [_array count];

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

	return OF_NOT_FOUND;
}

- (size_t)indexOfObjectIdenticalTo: (id)object
{
	id *objects;
	size_t i, count;
	size_t count;

	if (object == nil)
		return OF_NOT_FOUND;

	objects = [_array items];
	count = [_array count];

	for (i = 0; i < count; i++)
	for (size_t i = 0; i < count; i++)
		if (objects[i] == object)
			return i;

	return OF_NOT_FOUND;
}


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
322
323
324
325
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
322







-
+















-
+









-
+




-
+







						  range: range];
}

- (bool)isEqual: (id)object
{
	OFArray *otherArray;
	id const *objects, *otherObjects;
	size_t i, count;
	size_t count;

	if (![object isKindOfClass: [OFArray_adjacent class]] &&
	    ![object isKindOfClass: [OFMutableArray_adjacent class]])
		return [super isEqual: object];

	otherArray = object;

	count = [_array count];

	if (count != [otherArray count])
		return false;

	objects = [_array items];
	otherObjects = [otherArray objects];

	for (i = 0; i < count; i++)
	for (size_t i = 0; i < count; i++)
		if (![objects[i] isEqual: otherObjects[i]])
			return false;

	return true;
}

- (uint32_t)hash
{
	id *objects = [_array items];
	size_t i, count = [_array count];
	size_t count = [_array count];
	uint32_t hash;

	OF_HASH_INIT(hash);

	for (i = 0; i < count; i++)
	for (size_t i = 0; i < count; i++)
		OF_HASH_ADD_HASH(hash, [objects[i] hash]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

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







-
+


-
+







-
+

-
+







	return (int)count;
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	id *objects = [_array items];
	size_t i, count = [_array count];
	size_t count = [_array count];
	bool stop = false;

	for (i = 0; i < count && !stop; i++)
	for (size_t i = 0; i < count && !stop; i++)
		block(objects[i], i, &stop);
}
#endif

- (void)dealloc
{
	id *objects = [_array items];
	size_t i, count = [_array count];
	size_t count = [_array count];

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

	[_array release];

	[super dealloc];
}
@end