ObjFW  Check-in [eeec8af349]

Overview
Comment:OFDictionary: Add default for fast enumeration
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: eeec8af349b531b1753d3f7701748549b4739f9f18f963d05dd71d2bbdf3aca9
User & Date: js on 2019-06-19 00:36:35
Other Links: manifest | tags
Context
2019-06-19
00:45
OFEnumerator: Remove -[reset] check-in: 7214a2c7af user: js tags: trunk
00:36
OFDictionary: Add default for fast enumeration check-in: eeec8af349 user: js tags: trunk
2019-06-18
02:05
OFDictionary: Add default -[objectEnumerator] check-in: e2d0c876b4 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [b0c221b8b7] to [c70541cdfe].

518
519
520
521
522
523
524


525































526
527
528
529
530
531
532
	    initWithDictionary: self] autorelease];
}

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


	OF_UNRECOGNIZED_SELECTOR































}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateKeysAndObjectsUsingBlock:
    (of_dictionary_enumeration_block_t)block
{
	bool stop = false;







>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
	    initWithDictionary: self] autorelease];
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
			   objects: (id *)objects
			     count: (int)count
{
	OFEnumerator *enumerator;
	int i;

	memcpy(&enumerator, state->extra, sizeof(enumerator));

	if (enumerator == nil) {
		void *pool = objc_autoreleasePoolPush();

		enumerator = [[self keyEnumerator] retain];
		memcpy(state->extra, &enumerator, sizeof(enumerator));

		objc_autoreleasePoolPop(pool);
	}

	state->itemsPtr = objects;
	state->mutationsPtr = (unsigned long *)self;

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

	for (i = 0; i < count; i++) {
		id object = [enumerator nextObject];

		if (object == nil) {
			state->state = 1;
			[enumerator release];

			return i;
		}

		objects[i] = object;
	}

	return i;
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateKeysAndObjectsUsingBlock:
    (of_dictionary_enumeration_block_t)block
{
	bool stop = false;

Modified tests/OFDictionaryTests.m from [4a69123110] to [c3a18a2f55].

34
35
36
37
38
39
40

41
42
43
44
45
46
47
	OFMutableDictionary *_dictionary;
}
@end

@interface SimpleMutableDictionary: OFMutableDictionary
{
	OFMutableDictionary *_dictionary;

}
@end

@implementation SimpleDictionary
- (instancetype)init
{
	self = [super init];







>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	OFMutableDictionary *_dictionary;
}
@end

@interface SimpleMutableDictionary: OFMutableDictionary
{
	OFMutableDictionary *_dictionary;
	unsigned long _mutations;
}
@end

@implementation SimpleDictionary
- (instancetype)init
{
	self = [super init];
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141


142
143



144
145
146
147


148
















149
150
151
152
153
154
155
	return [_dictionary count];
}

- (OFEnumerator *)keyEnumerator
{
	return [_dictionary keyEnumerator];
}

- (OFEnumerator *)objectEnumerator
{
	return [_dictionary objectEnumerator];
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
			   objects: (id *)objects
			     count: (int)count
{
	return [_dictionary countByEnumeratingWithState: state
						objects: objects
						  count: count];
}
@end

@implementation SimpleMutableDictionary
+ (void)initialize
{
	if (self == [SimpleMutableDictionary class])
		[self inheritMethodsFromClass: [SimpleDictionary class]];
}

- (void)setObject: (id)object
	   forKey: (id)key
{


	[_dictionary setObject: object
			forKey: key];



}

- (void)removeObjectForKey: (id)key
{


	[_dictionary removeObjectForKey: key];
















}
@end

@implementation TestsAppDelegate (OFDictionaryTests)
- (void)dictionaryTestsWithClass: (Class)dictionaryClass
		    mutableClass: (Class)mutableDictionaryClass
{







<
<
<
<
<
<
<
<
<
<
<
<
<
<












>
>


>
>
>




>
>

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







110
111
112
113
114
115
116














117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
	return [_dictionary count];
}

- (OFEnumerator *)keyEnumerator
{
	return [_dictionary keyEnumerator];
}














@end

@implementation SimpleMutableDictionary
+ (void)initialize
{
	if (self == [SimpleMutableDictionary class])
		[self inheritMethodsFromClass: [SimpleDictionary class]];
}

- (void)setObject: (id)object
	   forKey: (id)key
{
	bool existed = ([_dictionary objectForKey: key] == nil);

	[_dictionary setObject: object
			forKey: key];

	if (existed)
		_mutations++;
}

- (void)removeObjectForKey: (id)key
{
	bool existed = ([_dictionary objectForKey: key] == nil);

	[_dictionary removeObjectForKey: key];

	if (existed)
		_mutations++;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
			   objects: (id *)objects
			     count: (int)count
{
	int ret = [super countByEnumeratingWithState: state
					     objects: objects
					       count: count];

	state->mutationsPtr = &_mutations;

	return ret;
}
@end

@implementation TestsAppDelegate (OFDictionaryTests)
- (void)dictionaryTestsWithClass: (Class)dictionaryClass
		    mutableClass: (Class)mutableDictionaryClass
{