ObjFW  Diff

Differences From Artifact [b27a848d5b]:

To Artifact [c800430259]:


35
36
37
38
39
40
41
42
43










44
45
46
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
	Class isa;
} placeholder;

@interface OFMutableArray_placeholder: OFMutableArray
@end

static void
quicksort(OFMutableArray *array, size_t left, size_t right)
{










	while (left < right) {
		size_t i, j;
		id pivot;

		i = left;
		j = right - 1;
		pivot = [array objectAtIndex: right];

		do {
			while ([[array objectAtIndex: i] compare: pivot] !=
			    OF_ORDERED_DESCENDING && i < right)
				i++;

			while ([[array objectAtIndex: j] compare: pivot] !=
			    OF_ORDERED_ASCENDING && j > left)
				j--;

			if (i < j)
				[array exchangeObjectAtIndex: i
					   withObjectAtIndex: j];
		} while (i < j);

		if ([[array objectAtIndex: i] compare: pivot] ==
		    OF_ORDERED_DESCENDING)
			[array exchangeObjectAtIndex: i
				   withObjectAtIndex: right];

		if (i > 0) {
			if (i > left && i - 1 - left > right - i - 1) {
				right = i - 1;
				quicksort(array, i + 1, right);
			} else {
				quicksort(array, left, i - 1);
				left = i + 1;
			}
		} else
			left = i + 1;
	}
}








|

>
>
>
>
>
>
>
>
>
>










|



|







|
<






|

|







35
36
37
38
39
40
41
42
43
44
45
46
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
	Class isa;
} placeholder;

@interface OFMutableArray_placeholder: OFMutableArray
@end

static void
quicksort(OFMutableArray *array, size_t left, size_t right, int options)
{
	of_comparison_result_t ascending, descending;

	if (options & OF_SORT_OPTIONS_DESCENDING) {
		ascending = OF_ORDERED_DESCENDING;
		descending = OF_ORDERED_ASCENDING;
	} else {
		ascending = OF_ORDERED_ASCENDING;
		descending = OF_ORDERED_DESCENDING;
	}

	while (left < right) {
		size_t i, j;
		id pivot;

		i = left;
		j = right - 1;
		pivot = [array objectAtIndex: right];

		do {
			while ([[array objectAtIndex: i] compare: pivot] !=
			    descending && i < right)
				i++;

			while ([[array objectAtIndex: j] compare: pivot] !=
			    ascending && j > left)
				j--;

			if (i < j)
				[array exchangeObjectAtIndex: i
					   withObjectAtIndex: j];
		} while (i < j);

		if ([[array objectAtIndex: i] compare: pivot] == descending)

			[array exchangeObjectAtIndex: i
				   withObjectAtIndex: right];

		if (i > 0) {
			if (i > left && i - 1 - left > right - i - 1) {
				right = i - 1;
				quicksort(array, i + 1, right, options);
			} else {
				quicksort(array, left, i - 1, options);
				left = i + 1;
			}
		} else
			left = i + 1;
	}
}

375
376
377
378
379
380
381





382
383
384
385
386
387
388
389
390
391
392
393
394
	} @finally {
		[object1 release];
	}
}

- (void)sort
{





	size_t count = [self count];

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

	quicksort(self, 0, count - 1);
}

- (void)reverse
{
	size_t i, j, count = [self count];

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







>
>
>
>
>





|







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
	} @finally {
		[object1 release];
	}
}

- (void)sort
{
	[self sortWithOptions: 0];
}

- (void)sortWithOptions: (int)options
{
	size_t count = [self count];

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

	quicksort(self, 0, count - 1, options);
}

- (void)reverse
{
	size_t i, j, count = [self count];

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