ObjFW  Diff

Differences From Artifact [6856cfe7f0]:

To Artifact [0b8584dc8f]:

  • File src/OFArray_adjacent.m — part of check-in [4dbca9fc06] at 2014-04-08 17:01:53 on branch trunk — OFArray_adjacent: Optimize fast enumeration

    This restores the previous behaviour for OFArray_adjacent. It was lost
    when OFArray's fast enumeration was changed to be better optimized for
    huge arrays that aren't adjacent in memory. I forgot that
    OFArray_adjacent just used the implementation from OFArray, as OFArray
    had the ideal implementation for OFArray_adjacent, but now that OFArray
    is optimized for huge, non-adjacent arrays, this wasn't the case
    anymore. (user: js, size: 7146) [annotate] [blame] [check-ins using]


326
327
328
329
330
331
332

























333
334
335
336
337
338
339
	for (i = 0; i < count; i++)
		OF_HASH_ADD_HASH(hash, [objects[i] hash]);

	OF_HASH_FINALIZE(hash);

	return hash;
}


























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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







326
327
328
329
330
331
332
333
334
335
336
337
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
	for (i = 0; i < count; i++)
		OF_HASH_ADD_HASH(hash, [objects[i] hash]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	size_t count = [_array count];

	if (count > INT_MAX)
		/*
		 * Use the implementation from OFArray, which is slower, but can
		 * enumerate in chunks.
		 */
		return [super countByEnumeratingWithState: state
						  objects: objects
						    count: count_];

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

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

	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];
	bool stop = false;