Overview
Comment: | OFSet: Add default method for fast enumeration |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f8b53e2f6bd460ea06df990b3072e43a |
User & Date: | js on 2019-06-20 23:45:11 |
Other Links: | manifest | tags |
Context
2019-06-20
| ||
23:47 | Avoid retaining enumerator during fast enumeration check-in: 13864f512c user: js tags: trunk | |
23:45 | OFSet: Add default method for fast enumeration check-in: f8b53e2f6b user: js tags: trunk | |
23:36 | Document methods to override in class clusters check-in: d537543238 user: js tags: trunk | |
Changes
Modified src/OFSet.m from [9b44169159] to [806937cb0f].
︙ | ︙ | |||
251 252 253 254 255 256 257 | OF_UNRECOGNIZED_SELECTOR } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | OF_UNRECOGNIZED_SELECTOR } - (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 objectEnumerator] 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; } - (bool)isEqual: (id)object { OFSet *set; if (object == self) |
︙ | ︙ |
Modified tests/OFSetTests.m from [984a5f0223] to [78f1739521].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | OFMutableSet *_set; } @end @interface SimpleMutableSet: OFMutableSet { OFMutableSet *_set; } @end @implementation SimpleSet - (instancetype)init { self = [super init]; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | OFMutableSet *_set; } @end @interface SimpleMutableSet: OFMutableSet { OFMutableSet *_set; unsigned long _mutations; } @end @implementation SimpleSet - (instancetype)init { self = [super init]; |
︙ | ︙ | |||
113 114 115 116 117 118 119 | return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } | < < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > | 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 166 167 | return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } @end @implementation SimpleMutableSet + (void)initialize { if (self == [SimpleMutableSet class]) [self inheritMethodsFromClass: [SimpleSet class]]; } - (void)addObject: (id)object { bool existed = [self containsObject: object]; [_set addObject: object]; if (existed) _mutations++; } - (void)removeObject: (id)object { bool existed = [self containsObject: object]; [_set removeObject: object]; if (existed) _mutations++; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { int ret = [_set countByEnumeratingWithState: state objects: objects count: count]; state->mutationsPtr = &_mutations; return ret; } @end @implementation TestsAppDelegate (OFSetTests) - (void)setTestsWithClass: (Class)setClass mutableClass: (Class)mutableSetClass { |
︙ | ︙ |