Differences From Artifact [e02a8ee9e6]:
- File src/OFMutableArray_adjacent.m — part of check-in [d1572ef036] at 2012-01-31 13:59:09 on branch trunk — Add -[removeAllObjects] and -[removeAllItems]. (user: js, size: 6518) [annotate] [blame] [check-ins using]
To Artifact [a923c5af53]:
- File
src/OFMutableArray_adjacent.m
— part of check-in
[008be86a16]
at
2012-03-12 11:54:22
on branch trunk
— OFArray: +[arrayWithCArray:length:] -> +[arrayWithObjects:count:].
This is required for the new array literals. (user: js, size: 6556) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
51 52 53 54 55 56 57 | mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { | | | | | | | | | | | | | | | | | | 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 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 | mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { id *objects = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objects[i] isEqual: oldObject]) { [newObject retain]; [objects[i] release]; objects[i] = newObject; return; } } } - (void)replaceObjectAtIndex: (size_t)index withObject: (id)object { id *objects = [array cArray]; id oldObject; if (index >= [array count]) @throw [OFOutOfRangeException exceptionWithClass: isa]; oldObject = objects[index]; objects[index] = [object retain]; [oldObject release]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { id *objects = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objects[i] == oldObject) { [newObject retain]; [objects[i] release]; objects[i] = newObject; return; } } } - (void)removeObject: (id)object { id *objects = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objects[i] isEqual: object]) { object = objects[i]; [array removeItemAtIndex: i]; mutations++; [object release]; return; } } } - (void)removeObjectIdenticalTo: (id)object { id *objects = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objects[i] == object) { [array removeItemAtIndex: i]; mutations++; [object release]; return; } |
︙ | ︙ | |||
143 144 145 146 147 148 149 | [object release]; mutations++; } - (void)removeNObjects: (size_t)nObjects { | | | | | | | | 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 168 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 197 198 199 | [object release]; mutations++; } - (void)removeNObjects: (size_t)nObjects { id *objects = [array cArray], *copy; size_t i, count = [array count]; if (nObjects > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; copy = [self allocMemoryForNItems: nObjects ofSize: sizeof(id)]; memcpy(copy, objects + (count - nObjects), nObjects * sizeof(id)); @try { [array removeNItems: nObjects]; mutations++; for (i = 0; i < nObjects; i++) [copy[i] release]; } @finally { [self freeMemory: copy]; } } - (void)removeAllObjects { id *objects = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) [objects[i] release]; [array removeAllItems]; } - (void)removeObjectsInRange: (of_range_t)range { id *objects = [array cArray], *copy; size_t i, count = [array count]; if (range.length > count - range.start) @throw [OFOutOfRangeException exceptionWithClass: isa]; copy = [self allocMemoryForNItems: range.length ofSize: sizeof(id)]; memcpy(copy, objects + range.start, range.length * sizeof(id)); @try { [array removeNItems: range.length atIndex: range.start]; mutations++; for (i = 0; i < range.length; i++) |
︙ | ︙ | |||
211 212 213 214 215 216 217 | mutations++; } - (void)swapObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2 { | | | | | | | | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | mutations++; } - (void)swapObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2 { id *objects = [array cArray]; size_t count = [array count]; id tmp; if (index1 >= count || index2 >= count) @throw [OFOutOfRangeException exceptionWithClass: isa]; tmp = objects[index1]; objects[index1] = objects[index2]; objects[index2] = tmp; } - (void)reverse { id *objects = [array cArray]; size_t i, j, count = [array count]; if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) { id tmp = objects[i]; objects[i] = objects[j]; objects[j] = tmp; } } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count { |
︙ | ︙ | |||
266 267 268 269 270 271 272 | initWithArray: self mutationsPtr: &mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { | | | | | | | | 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | initWithArray: self mutationsPtr: &mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; unsigned long mutations2 = mutations; for (i = 0; i < count && !stop; i++) { if (mutations != mutations2) @throw [OFEnumerationMutationException exceptionWithClass: isa object: self]; block(objects[i], i, &stop); } } - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { id *objects = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; unsigned long mutations2 = mutations; for (i = 0; i < count && !stop; i++) { id newObject; if (mutations != mutations2) @throw [OFEnumerationMutationException exceptionWithClass: isa object: self]; newObject = block(objects[i], i, &stop); if (newObject == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; [newObject retain]; [objects[i] release]; objects[i] = newObject; } } #endif - (void)makeImmutable { isa = [OFArray_adjacent class]; } @end |