ObjFW  Check-in [4dbca9fc06]

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4dbca9fc06512af2ab1e5aef053444ca8e7f2876af97f801f56f3497502aa796
User & Date: js on 2014-04-08 17:01:53
Other Links: manifest | tags
Context
2014-04-08
18:48
Partly revert 4a8704e check-in: 82b11a2992 user: js tags: trunk
17:01
OFArray_adjacent: Optimize fast enumeration check-in: 4dbca9fc06 user: js tags: trunk
16:38
runtime/hashtable.m: Move some code around check-in: f447af977a user: js tags: trunk
Changes

Modified src/OFArray_adjacent.m from [6856cfe7f0] to [0b8584dc8f].

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;

Modified src/OFMutableArray_adjacent.m from [7139dbd166] to [dd32892024].

296
297
298
299
300
301
302
303
304



305
306
307
308


309
310
311
312


313






314
315
316
317
318
319
320
321
322
323
		objects[i] = objects[j];
		objects[j] = tmp;
	}
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{



	/*
	 * Super means the implementation from OFArray here, as OFMutableArray
	 * does not reimplement it. As OFArray_adjacent does not reimplement it
	 * either, this is fine.


	 */
	int ret = [super countByEnumeratingWithState: state
					     objects: objects
					       count: count];









	state->mutationsPtr = &_mutations;

	return ret;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFArrayEnumerator alloc]
	    initWithArray: self
	     mutationsPtr: &_mutations] autorelease];







|

>
>
>
|
|
<
<
>
>
|
|
|
|
>
>
|
>
>
>
>
>
>


|







296
297
298
299
300
301
302
303
304
305
306
307
308
309


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
		objects[i] = objects[j];
		objects[j] = tmp;
	}
}

- (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 (OFMutableArray does not


		 * have one), which is slower, but can enumerate in chunks, and
		 * set the mutations pointer.
		 */
		int ret = [super countByEnumeratingWithState: state
						     objects: objects
						       count: count_];
		state->mutationsPtr = &_mutations;
		return ret;
	}

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

	state->state = count;
	state->itemsPtr = [_array items];
	state->mutationsPtr = &_mutations;

	return (int)count;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFArrayEnumerator alloc]
	    initWithArray: self
	     mutationsPtr: &_mutations] autorelease];