Overview
Comment: | Add -[allKeys] and -[allObjects] to OFDictionary. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
cc87fcff36c485afc129bfe95dc3cd44 |
User & Date: | js on 2011-07-21 19:03:06 |
Other Links: | manifest | tags |
Context
2011-07-21
| ||
19:17 | Add -[minusSet:] and -[intersectSet:] to OFMutableSet. check-in: 821456272f user: js tags: trunk | |
19:03 | Add -[allKeys] and -[allObjects] to OFDictionary. check-in: cc87fcff36 user: js tags: trunk | |
2011-07-20
| ||
18:23 | Remove code duplication for fast enumeration of mutable collections. check-in: 63fc941b66 user: js tags: trunk | |
Changes
Modified src/OFDictionary.h from [cbf0132485] to [fe68e3c105].
︙ | ︙ | |||
169 170 171 172 173 174 175 176 177 178 179 180 181 182 | * * \param object The object which is checked for being in the dictionary * \return A boolean whether the dictionary contains an object with the * specified address. */ - (BOOL)containsObjectIdenticalTo: (id)object; /** * \brief Returns an OFEnumerator to enumerate through the dictionary's keys. * * \return An OFEnumerator to enumerate through the dictionary's keys */ - (OFEnumerator*)keyEnumerator; | > > > > > > > > > > > > > > | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | * * \param object The object which is checked for being in the dictionary * \return A boolean whether the dictionary contains an object with the * specified address. */ - (BOOL)containsObjectIdenticalTo: (id)object; /** * \brief Returns an array of all keys. * * \return An array of all keys */ - (OFArray*)allKeys; /** * \brief Returns an array of all objects. * * \return An array of all objects */ - (OFArray*)allObjects; /** * \brief Returns an OFEnumerator to enumerate through the dictionary's keys. * * \return An OFEnumerator to enumerate through the dictionary's keys */ - (OFEnumerator*)keyEnumerator; |
︙ | ︙ |
Modified src/OFDictionary.m from [78f590ebf2] to [b5e17c6561].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #import "OFDictionary.h" #import "OFEnumerator.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" | > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #include <assert.h> #import "OFDictionary.h" #import "OFEnumerator.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" |
︙ | ︙ | |||
636 637 638 639 640 641 642 643 644 645 646 647 648 649 | for (i = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED && data[i]->object == object) return YES; return NO; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { int i; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | for (i = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED && data[i]->object == object) return YES; return NO; } - (OFArray*)allKeys { OFArray *ret; id *cArray = [self allocMemoryForNItems: count withSize: sizeof(id)]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) cArray[j++] = data[i]->key; assert(j == count); @try { ret = [OFArray arrayWithCArray: cArray length: count]; } @finally { [self freeMemory: cArray]; } return ret; } - (OFArray*)allObjects { OFArray *ret; id *cArray = [self allocMemoryForNItems: count withSize: sizeof(id)]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) cArray[j++] = data[i]->object; assert(j == count); @try { ret = [OFArray arrayWithCArray: cArray length: count]; } @finally { [self freeMemory: cArray]; } return ret; } - (OFEnumerator*)objectEnumerator { return [[[OFDictionaryObjectEnumerator alloc] initWithDictionary: self data: data size: size mutationsPointer: NULL] autorelease]; } - (OFEnumerator*)keyEnumerator { return [[[OFDictionaryKeyEnumerator alloc] initWithDictionary: self data: data size: size mutationsPointer: NULL] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { int i; |
︙ | ︙ | |||
660 661 662 663 664 665 666 | state->itemsPtr = objects; state->mutationsPtr = (unsigned long*)self; return i; } | < < < < < < < < < < < < < < < < < < | 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | state->itemsPtr = objects; state->mutationsPtr = (unsigned long*)self; return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (of_dictionary_enumeration_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; BOOL stop = NO; |
︙ | ︙ |
Modified tests/OFDictionaryTests.m from [f1e6cab4f8] to [127b7e8b9a].
︙ | ︙ | |||
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | [dict containsObjectIdenticalTo: [OFString stringWithString: values[0]]] == NO) TEST(@"-[description]", [[dict description] isEqual: @"{\n\tkey1 = value1;\n\tkey2 = value2;\n}"]) TEST(@"-[keyEnumerator]", (key_enum = [dict keyEnumerator])) TEST(@"-[objectEnumerator]", (obj_enum = [dict objectEnumerator])) TEST(@"OFEnumerator's -[nextObject]", [[key_enum nextObject] isEqual: keys[0]] && [[obj_enum nextObject] isEqual: values[0]] && [[key_enum nextObject] isEqual: keys[1]] && | > > > > > > > > | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | [dict containsObjectIdenticalTo: [OFString stringWithString: values[0]]] == NO) TEST(@"-[description]", [[dict description] isEqual: @"{\n\tkey1 = value1;\n\tkey2 = value2;\n}"]) TEST(@"-[allKeys]", [[dict allKeys] isEqual: ([OFArray arrayWithObjects: keys[0], keys[1], nil])]) TEST(@"-[allObjects]", [[dict allObjects] isEqual: ([OFArray arrayWithObjects: values[0], values[1], nil])]) TEST(@"-[keyEnumerator]", (key_enum = [dict keyEnumerator])) TEST(@"-[objectEnumerator]", (obj_enum = [dict objectEnumerator])) TEST(@"OFEnumerator's -[nextObject]", [[key_enum nextObject] isEqual: keys[0]] && [[obj_enum nextObject] isEqual: values[0]] && [[key_enum nextObject] isEqual: keys[1]] && |
︙ | ︙ |