ObjFW  Diff

Differences From Artifact [3601f4b0dd]:

To Artifact [208e599910]:


19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39







-






+







#include <stdarg.h>

#import "OFArray.h"
#import "OFArray_subarray.h"
#import "OFArray_adjacent.h"
#import "OFString.h"
#import "OFXMLElement.h"
#import "OFAutoreleasePool.h"

#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "macros.h"

static struct {
	Class isa;
} placeholder;

@interface OFArray_placeholder: OFArray
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
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







-
+













-
+


+
-
+

-




-
+






-
+







	return [self componentsJoinedByString: separator
				usingSelector: @selector(description)];
}

- (OFString*)componentsJoinedByString: (OFString*)separator
			usingSelector: (SEL)selector
{
	OFAutoreleasePool *pool, *pool2;
	void *pool;
	OFMutableString *ret;
	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];
	pool = objc_autoreleasePoolPush();
	objects = [self objects];

	for (i = 0; i < count - 1; i++) {
	pool2 = [[OFAutoreleasePool alloc] init];
		void *pool2 = objc_autoreleasePoolPush();

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

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

	[ret makeImmutable];

	[pool release];
	objc_autoreleasePoolPop(pool);

	return ret;
}

- (BOOL)isEqual: (id)object
{
	/* FIXME: Optimize (for example, buffer of 16 for each) */
440
441
442
443
444
445
446
447

448
449
450
451
452
453

454
455
456
457
458
459
460
461
462
463
464
465
466

467
468
469
470
471

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


500
501

502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519


520

521
522
523
524
525
526
527
440
441
442
443
444
445
446

447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468

469

470
471
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
500
501
502
503

504
505
506
507
508
509


510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525







-
+





-
+












-
+


-

-
+




-
-
+











+
-
+

-


-
+



-
-
+
+

-
+




-
+





-
-






+
+
-
+







	OF_HASH_FINALIZE(hash);

	return hash;
}

- (OFString*)description
{
	OFAutoreleasePool *pool;
	void *pool;
	OFMutableString *ret;

	if ([self count] == 0)
		return @"()";

	pool = [[OFAutoreleasePool alloc] init];
	pool = objc_autoreleasePoolPush();
	ret = [[self componentsJoinedByString: @",\n"] mutableCopy];

	@try {
		[ret prependString: @"(\n"];
		[ret replaceOccurrencesOfString: @"\n"
				     withString: @"\n\t"];
		[ret appendString: @"\n)"];
	} @catch (id e) {
		[ret release];
		@throw e;
	}

	[pool release];
	objc_autoreleasePoolPop(pool);

	[ret makeImmutable];
	[ret autorelease];

	return ret;
	return [ret autorelease];
}

- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFAutoreleasePool *pool2;
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *element;
	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];

	for (i = 0; i < count; i++) {
	pool2 = [[OFAutoreleasePool alloc] init];
		void *pool2 = objc_autoreleasePoolPush();

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

		[pool2 releaseObjects];
		objc_autoreleasePoolPop(pool2);
	}

	[element retain];
	[pool release];
	[element autorelease];

	objc_autoreleasePoolPop(pool);

	return element;
	return [element autorelease];
}

- (OFString*)JSONRepresentation
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();
	OFMutableString *JSON;

	JSON = [[self componentsJoinedByString: @","
				 usingSelector: @selector(JSONRepresentation)]
	    mutableCopy];
	[pool release];
	[JSON autorelease];

	[JSON prependString: @"["];
	[JSON appendString: @"]"];

	[JSON makeImmutable];

	objc_autoreleasePoolPop(pool);

	return JSON;
	return [JSON autorelease];
}

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