ObjFW  Diff

Differences From Artifact [6919605399]:

To Artifact [652b854188]:


71
72
73
74
75
76
77
78

79
80
81
82
83
84

85
86
87


88
89
90
91
92
93
94
71
72
73
74
75
76
77

78






79
80


81
82
83
84
85
86
87
88
89







-
+
-
-
-
-
-
-
+

-
-
+
+







}

- initWithArray: (OFArray*)array
{
	return (id)[[OFArray_adjacent alloc] initWithArray: array];
}

- initWithCArray: (id*)objects
- initWithObjects: (id*)objects
{
	return (id)[[OFArray_adjacent alloc] initWithCArray: objects];
}

- initWithCArray: (id*)objects
	  length: (size_t)length
	    count: (size_t)count
{
	return (id)[[OFArray_adjacent alloc] initWithCArray: objects
						     length: length];
	return (id)[[OFArray_adjacent alloc] initWithObjects: objects
						       count: count];
}

- initWithSerialization: (OFXMLElement*)element
{
	return (id)[[OFArray_adjacent alloc] initWithSerialization: element];
}

153
154
155
156
157
158
159
160

161
162
163
164
165
166

167
168
169


170
171
172
173
174
175
176
148
149
150
151
152
153
154

155






156
157


158
159
160
161
162
163
164
165
166







-
+
-
-
-
-
-
-
+

-
-
+
+







}

+ arrayWithArray: (OFArray*)array
{
	return [[[self alloc] initWithArray: array] autorelease];
}

+ arrayWithCArray: (id*)objects
+ arrayWithObjects: (id*)objects
{
	return [[[self alloc] initWithCArray: objects] autorelease];
}

+ arrayWithCArray: (id*)objects
	   length: (size_t)length
	     count: (size_t)count
{
	return [[[self alloc] initWithCArray: objects
				      length: length] autorelease];
	return [[[self alloc] initWithObjects: objects
					count: count] autorelease];
}

- init
{
	if (isa == [OFArray class]) {
		Class c = isa;
		[self release];
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
202
203
204
205
206
207
208

209









210
211
212
213
214
215
216
217







-
+
-
-
-
-
-
-
-
-
-
+







{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithCArray: (id*)objects
- initWithObjects: (id*)objects
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithCArray: (id*)objects
	  length: (size_t)length
	    count: (size_t)count
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248







-
+







{
	size_t i;

	for (i = 0; i < range.length; i++)
		buffer[i] = [self objectAtIndex: range.start + i];
}

- (id*)cArray
- (id*)objects
{
	OFObject *container;
	size_t count;
	id *buffer;

	container = [[[OFObject alloc] init] autorelease];
	count = [self count];
284
285
286
287
288
289
290





291
292
293
294
295
296
297
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284







+
+
+
+
+







}

- (id)objectAtIndex: (size_t)index
{
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (id)objectAtIndexedSubscript: (size_t)index
{
	return [self objectAtIndex: index];
}

- (size_t)indexOfObject: (id)object
{
	size_t i, count = [self count];

	for (i = 0; i < count; i++)
		if ([[self objectAtIndex: i] isEqual: object])
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
378

379
380
381
382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397

398
399
400
401
402
403

404
405
406
407
408
409
410
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

378
379
380
381
382
383

384
385
386
387
388
389

390
391
392
393
394
395
396
397







-
-
+
+


















-
+












-
+





-
+





-
+







	buffer = [self allocMemoryForNItems: range.length
				     ofSize: sizeof(*buffer)];

	@try {
		[self getObjects: buffer
			 inRange: range];

		ret = [OFArray arrayWithCArray: buffer
					length: range.length];
		ret = [OFArray arrayWithObjects: buffer
					  count: range.length];
	} @finally {
		[self freeMemory: buffer];
	}

	return ret;
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	return [self componentsJoinedByString: separator
				usingSelector: @selector(description)];
}

- (OFString*)componentsJoinedByString: (OFString*)separator
			usingSelector: (SEL)selector
{
	OFAutoreleasePool *pool, *pool2;
	OFMutableString *ret;
	id *cArray;
	id *objects;
	size_t i, count = [self count];
	IMP append;

	if (count == 0)
		return @"";
	if (count == 1)
		return [[self firstObject] performSelector: selector];

	ret = [OFMutableString string];
	append = [ret methodForSelector: @selector(appendString:)];

	pool = [[OFAutoreleasePool alloc] init];
	cArray = [self cArray];
	objects = [self objects];

	pool2 = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count - 1; i++) {
		append(ret, @selector(appendString:),
		    [cArray[i] performSelector: selector]);
		    [objects[i] performSelector: selector]);
		append(ret, @selector(appendString:), separator);

		[pool2 releaseObjects];
	}
	append(ret, @selector(appendString:),
	    [cArray[i] performSelector: selector]);
	    [objects[i] performSelector: selector]);

	[ret makeImmutable];

	[pool release];

	return ret;
}
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445

446
447
448
449
450
451
452
418
419
420
421
422
423
424

425
426
427
428
429
430
431

432
433
434
435
436
437
438
439







-
+






-
+







			return NO;

	return YES;
}

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

	OF_HASH_INIT(hash);

	for (i = 0; i < count; i++) {
		uint32_t h = [cArray[i] hash];
		uint32_t h = [objects[i] hash];

		OF_HASH_ADD(hash, h >> 24);
		OF_HASH_ADD(hash, (h >> 16) & 0xFF);
		OF_HASH_ADD(hash, (h >> 8) & 0xFF);
		OF_HASH_ADD(hash, h & 0xFF);
	}

485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499







-
+












-
+







}

- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFAutoreleasePool *pool2;
	OFXMLElement *element;
	id <OFSerialization> *cArray = [self cArray];
	id <OFSerialization> *objects = [self objects];
	size_t i, count = [self count];

	if ([self isKindOfClass: [OFMutableArray class]])
		element = [OFXMLElement elementWithName: @"OFMutableArray"
					      namespace: OF_SERIALIZATION_NS];
	else
		element = [OFXMLElement elementWithName: @"OFArray"
					      namespace: OF_SERIALIZATION_NS];

	pool2 = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count; i++) {
		[element addChild: [cArray[i] XMLElementBySerializing]];
		[element addChild: [objects[i] XMLElementBySerializing]];

		[pool2 releaseObjects];
	}

	[element retain];
	[pool release];
	[element autorelease];
531
532
533
534
535
536
537
538

539
540
541
542
543


544
545
546
547
548
549

550
551
552
553
554


555
556
557
558
559
560
561
518
519
520
521
522
523
524

525
526
527
528


529
530
531
532
533
534
535

536
537
538
539


540
541
542
543
544
545
546
547
548







-
+



-
-
+
+





-
+



-
-
+
+







	[JSON makeImmutable];

	return JSON;
}

- (void)makeObjectsPerformSelector: (SEL)selector
{
	id *cArray = [self cArray];
	id *objects = [self objects];
	size_t i, count = [self count];

	for (i = 0; i < count; i++)
		((void(*)(id, SEL))[cArray[i]
		    methodForSelector: selector])(cArray[i], selector);
		((void(*)(id, SEL))[objects[i]
		    methodForSelector: selector])(objects[i], selector);
}

- (void)makeObjectsPerformSelector: (SEL)selector
			withObject: (id)object
{
	id *cArray = [self cArray];
	id *objects = [self objects];
	size_t i, count = [self count];

	for (i = 0; i < count; i++)
		((void(*)(id, SEL, id))[cArray[i]
		    methodForSelector: selector])(cArray[i], selector, object);
		((void(*)(id, SEL, id))[objects[i]
		    methodForSelector: selector])(objects[i], selector, object);
}

- (OFArray*)sortedArray
{
	OFMutableArray *new = [[self mutableCopy] autorelease];

	[new sort];
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
573
574
575
576
577
578
579

580
581
582
583
584
585
586
587







-
+







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

	if (state->state >= count)
		return 0;

	state->state = count;
	state->itemsPtr = [self cArray];
	state->itemsPtr = [self objects];
	state->mutationsPtr = (unsigned long*)self;

	return (int)count;
}

- (OFEnumerator*)objectEnumerator
{
627
628
629
630
631
632
633
634
635


636
637
638
639
640
641
642
614
615
616
617
618
619
620


621
622
623
624
625
626
627
628
629







-
-
+
+








	@try {
		[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
		    BOOL *stop) {
			tmp[index] = block(object, index);
		}];

		ret = [OFArray arrayWithCArray: tmp
					length: count];
		ret = [OFArray arrayWithObjects: tmp
					  count: count];
	} @finally {
		[self freeMemory: tmp];
	}

	return ret;
}

652
653
654
655
656
657
658
659
660


661
662
663
664
665
666
667
639
640
641
642
643
644
645


646
647
648
649
650
651
652
653
654







-
-
+
+








		[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
		    BOOL *stop) {
			if (block(object, index))
				tmp[i++] = object;
		}];

		ret = [OFArray arrayWithCArray: tmp
					length: i];
		ret = [OFArray arrayWithObjects: tmp
					  count: i];
	} @finally {
		[self freeMemory: tmp];
	}

	return ret;
}