Differences From Artifact [fae9385bda]:
- File src/OFDictionary.m — part of check-in [5329fe7c1a] at 2015-06-12 23:59:20 on branch trunk — Add support for and use the new ObjC generics (user: js, size: 15362) [annotate] [blame] [check-ins using]
To Artifact [f9d2ed8c00]:
- File
src/OFDictionary.m
— part of check-in
[6b13727ce0]
at
2015-11-29 14:02:11
on branch trunk
— Make use of fast enumeration
Now that we require GCC >= 4.6 anyway, there's no more reason to not use
it anymore. (user: js, size: 15361) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
297 298 299 300 301 302 303 | return [[OFMutableDictionary alloc] initWithDictionary: self]; } - (bool)isEqual: (id)object { OFDictionary *otherDictionary; void *pool; | | | > > | | | < < > | 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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | return [[OFMutableDictionary alloc] initWithDictionary: self]; } - (bool)isEqual: (id)object { OFDictionary *otherDictionary; void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; id key; if (![object isKindOfClass: [OFDictionary class]]) return false; otherDictionary = object; if ([otherDictionary count] != [self count]) return false; pool = objc_autoreleasePoolPush(); keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { id otherObject = [otherDictionary objectForKey: key]; if (otherObject == nil || ![otherObject isEqual: object]) { objc_autoreleasePoolPop(pool); return false; } } objc_autoreleasePoolPop(pool); return true; } - (bool)containsObject: (id)object { void *pool; OFEnumerator *enumerator; id currentObject; if (object == nil) return false; pool = objc_autoreleasePoolPush(); enumerator = [self objectEnumerator]; while ((currentObject = [enumerator nextObject]) != nil) { if ([currentObject isEqual: object]) { objc_autoreleasePoolPop(pool); return true; } } |
︙ | ︙ | |||
360 361 362 363 364 365 366 | OFEnumerator *enumerator; id currentObject; if (object == nil) return false; pool = objc_autoreleasePoolPush(); | < > < < < | < < | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | OFEnumerator *enumerator; id currentObject; if (object == nil) return false; pool = objc_autoreleasePoolPush(); enumerator = [self objectEnumerator]; while ((currentObject = [enumerator nextObject]) != nil) { if (currentObject == object) { objc_autoreleasePoolPop(pool); return true; } } objc_autoreleasePoolPop(pool); return false; } - (OFArray*)allKeys { OFMutableArray *ret = [OFMutableArray arrayWithCapacity: [self count]]; for (id key in self) [ret addObject: key]; [ret makeImmutable]; return ret; } - (OFArray*)allObjects { OFMutableArray *ret = [OFMutableArray arrayWithCapacity: [self count]]; void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
425 426 427 428 429 430 431 | - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { OF_UNRECOGNIZED_SELECTOR } | | < < | 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | - (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; for (id key in self) { block(key, [self objectForKey: key], &stop); if (stop) break; } } - (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [new setObject: block(key, object) |
︙ | ︙ | |||
477 478 479 480 481 482 483 | return new; } #endif - (uint32_t)hash { void *pool = objc_autoreleasePoolPush(); | | > | > | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | return new; } #endif - (uint32_t)hash { void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; id key, object; uint32_t hash = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { hash += [key hash]; hash += [object hash]; } objc_autoreleasePoolPop(pool); return hash; } |
︙ | ︙ |