ObjFW  Diff

Differences From Artifact [3de2dc55f8]:

To Artifact [b0dfbc26ff]:


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







-
+









-
+







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

- (id const *)objects
{
	size_t count = self.count;
	id *buffer = of_alloc(count, sizeof(id));
	id *buffer = OFAllocMemory(count, sizeof(id));

	@try {
		[self getObjects: buffer inRange: OFRangeMake(0, count)];

		return [[OFData dataWithItemsNoCopy: buffer
					      count: count
					   itemSize: sizeof(id)
				       freeWhenDone: true] items];
	} @catch (id e) {
		free(buffer);
		OFFreeMemory(buffer);
		@throw e;
	}
}

- (id)copy
{
	return [self retain];
372
373
374
375
376
377
378
379

380
381
382
383
384
385

386
387
388
389
390
391
392
372
373
374
375
376
377
378

379
380
381
382
383
384

385
386
387
388
389
390
391
392







-
+





-
+







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

	if (![self isKindOfClass: [OFMutableArray class]])
		return [OFSubarray arrayWithArray: self range: range];

	buffer = of_alloc(range.length, sizeof(*buffer));
	buffer = OFAllocMemory(range.length, sizeof(*buffer));
	@try {
		[self getObjects: buffer inRange: range];

		ret = [OFArray arrayWithObjects: buffer count: range.length];
	} @finally {
		free(buffer);
		OFFreeMemory(buffer);
	}

	return ret;
}

- (OFString *)componentsJoinedByString: (OFString *)separator
{
821
822
823
824
825
826
827
828

829
830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845
846
847
848

849
850
851
852
853
854
855
856
857
858
859
860
861

862
863
864
865
866
867
868
821
822
823
824
825
826
827

828
829
830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856
857
858
859
860

861
862
863
864
865
866
867
868







-
+









-
+









-
+












-
+







}

#ifdef OF_HAVE_BLOCKS
- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block
{
	OFArray *ret;
	size_t count = self.count;
	id *tmp = of_alloc(count, sizeof(id));
	id *tmp = OFAllocMemory(count, sizeof(id));

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

		ret = [OFArray arrayWithObjects: tmp count: count];
	} @finally {
		free(tmp);
		OFFreeMemory(tmp);
	}

	return ret;
}

- (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block
{
	OFArray *ret;
	size_t count = self.count;
	id *tmp = of_alloc(count, sizeof(id));
	id *tmp = OFAllocMemory(count, sizeof(id));

	@try {
		__block size_t i = 0;

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

		ret = [OFArray arrayWithObjects: tmp count: i];
	} @finally {
		free(tmp);
		OFFreeMemory(tmp);
	}

	return ret;
}

- (id)foldUsingBlock: (OFArrayFoldBlock)block
{