Overview
Comment: | Only handle the first matching object in OFMutalbeArray operations.
This only makes sense as we use "Object" in the method names, implying |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
de45535c23983c1f258c37cbcadb97bf |
User & Date: | js on 2010-09-19 02:34:10 |
Other Links: | manifest | tags |
Context
2010-09-19
| ||
02:52 | Improve OFStreamObserver. check-in: b554732eae user: js tags: trunk | |
02:34 | Only handle the first matching object in OFMutalbeArray operations. check-in: de45535c23 user: js tags: trunk | |
02:05 | Update buildsys. check-in: c3cc5bb657 user: js tags: trunk | |
Changes
Modified src/OFMutableArray.h from [a52014b3ad] to [cb7ba1bfa9].
︙ | ︙ | |||
36 37 38 39 40 41 42 | * \param obj An object to add * \param index The index where the object should be added */ - (void)addObject: (id)obj atIndex: (size_t)index; /** | | < | | | | | | < | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | * \param obj An object to add * \param index The index where the object should be added */ - (void)addObject: (id)obj atIndex: (size_t)index; /** * Replaces the first object equivalent to the first specified object with the * second specified object. * * \param old The object to replace * \param new The replacement object */ - (void)replaceObject: (id)old withObject: (id)new_; /** * Replaces the object at the specified index with the specified object. * * \param index The index of the object to replace * \param obj The replacement object */ - (void)replaceObjectAtIndex: (size_t)index withObject: (id)obj; /** * Replaces the first object that has the same address as the first specified * object with the second specified object. * * \param old The object to replace * \param new The replacement object */ - (void)replaceObjectIdenticalTo: (id)old withObject: (id)new_; /** * Removes the first object equivalent to the specified object. * * \param obj The object to remove */ - (void)removeObject: (id)obj; /** * Removes the first object that has the same address as the specified object. * * \param obj The object to remove */ - (void)removeObjectIdenticalTo: (id)obj; /** * Removes the object at the specified index. * * \param index The index of the object to remove */ - (void)removeObjectAtIndex: (size_t)index; /** * Removes the specified amount of objects from the end of the OFArray. * * \param nobjects The number of objects to remove */ - (void)removeNObjects: (size_t)nobjects; |
︙ | ︙ |
Modified src/OFMutableArray.m from [cd027f3f1d] to [c66c422e10].
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 70 71 | size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objs[i] isEqual: old]) { [new retain]; [objs[i] release]; objs[i] = new; } } } | > > | | < | > > < < < < < < | < < < < < < < < < < | < < < < | < < | > < > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 | size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objs[i] isEqual: old]) { [new retain]; [objs[i] release]; objs[i] = new; return; } } } - (void)replaceObjectAtIndex: (size_t)index withObject: (id)obj { id *objs = [array cArray]; id old; if (index >= [array count]) @throw [OFOutOfRangeException newWithClass: isa]; old = objs[index]; objs[index] = [obj retain]; [old release]; } - (void)replaceObjectIdenticalTo: (id)old withObject: (id)new { id *objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objs[i] == old) { [new retain]; [objs[i] release]; objs[i] = new; return; } } } - (void)removeObject: (id)obj { id *objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objs[i] isEqual: obj]) { id obj = objs[i]; [array removeItemAtIndex: i]; mutations++; [obj release]; return; } } } - (void)removeObjectIdenticalTo: (id)obj { id *objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objs[i] == obj) { [array removeItemAtIndex: i]; mutations++; [obj release]; return; } } } - (void)removeObjectAtIndex: (size_t)index { id old = [self objectAtIndex: index]; [array removeItemAtIndex: index]; [old release]; mutations++; } - (void)removeNObjects: (size_t)nobjects { id *objs = [array cArray], *copy; size_t i, count = [array count]; |
︙ | ︙ |
Modified tests/OFArrayTests.m from [415ab0ae8e] to [895b4e152f].
︙ | ︙ | |||
83 84 85 86 87 88 89 | [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[replaceObject:identicalTo:]", R([m[0] replaceObjectIdenticalTo: c_ary[0] withObject: c_ary[1]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[1]] && | | | | | | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[replaceObject:identicalTo:]", R([m[0] replaceObjectIdenticalTo: c_ary[0] withObject: c_ary[1]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[1]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[replaceObjectAtIndex:withObject:]", R([m[0] replaceObjectAtIndex: 0 withObject: c_ary[0]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[removeObject:]", R([m[0] removeObject: c_ary[0]]) && [m[0] count] == 2) TEST(@"-[removeObjectIdenticalTo:]", R([m[0] removeObjectIdenticalTo: c_ary[2]]) && [m[0] count] == 1) [m[0] addObject: c_ary[0]]; [m[0] addObject: c_ary[1]]; TEST(@"-[removeNObjects:]", R([m[0] removeNObjects: 2]) && [m[0] count] == 1 && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]]) m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", R([m[1] removeObjectAtIndex: 1]) && [m[1] count] == 2 && [[m[1] objectAtIndex: 1] isEqual: c_ary[2]]) m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeNObjects:atIndex:]", R([m[1] removeNObjects: 2 atIndex: 0]) && [m[1] count] == 1 && [[m[1] objectAtIndex: 0] isEqual: c_ary[2]]) |
︙ | ︙ |