Overview
Comment: | Add -[removeObjectAtIndex] and -[removeNObjects:atIndex:] to OFArray. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0b6fc2523a423660898f1664da253b2f |
User & Date: | js on 2009-11-22 15:44:57 |
Other Links: | manifest | tags |
Context
2009-11-22
| ||
16:33 | Add -[drain] to OFAutoreleasePool. check-in: 2f85ceeed7 user: js tags: trunk | |
15:44 | Add -[removeObjectAtIndex] and -[removeNObjects:atIndex:] to OFArray. check-in: 0b6fc2523a user: js tags: trunk | |
2009-11-19
| ||
15:41 | Add -[removeItemAtIndex:] and -[removeNItems:atIndex:] to OFDataArray. check-in: 24928c1da1 user: js tags: trunk | |
Changes
Modified src/OFArray.h from [85afc7a10e] to [44d57c9221].
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 | /** * \return The last object of the OFDataArray */ - (id)lastObject; - addObject: (OFObject*)obj; - removeNObjects: (size_t)nobjects; @end #import "OFMutableArray.h" | > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | /** * \return The last object of the OFDataArray */ - (id)lastObject; - addObject: (OFObject*)obj; - removeObjectAtIndex: (size_t)index; - removeNObjects: (size_t)nobjects; - removeNObjects: (size_t)nobjects atIndex: (size_t)index; @end #import "OFMutableArray.h" |
Modified src/OFArray.m from [70a48a8714] to [f37fb0932b].
︙ | ︙ | |||
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | for (i = 0; i < len; i++) if (![objs[i] isEqual: objs2[i]]) return NO; return YES; } - (void)dealloc { OFObject **objs; size_t len, i; if (array != nil) { | > > > > > > > > > > > > > > > > > > > > > > | 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | for (i = 0; i < len; i++) if (![objs[i] isEqual: objs2[i]]) return NO; return YES; } - (uint32_t)hash { OFObject **carray = [array cArray]; size_t i, count = [array count]; uint32_t hash; OF_HASH_INIT(hash); for (i = 0; i < count; i++) { uint32_t h = [carray[i] hash]; OF_HASH_ADD(hash, h >> 24); OF_HASH_ADD(hash, (h >> 16) & 0xFF); OF_HASH_ADD(hash, (h >> 8) & 0xFF); OF_HASH_ADD(hash, h & 0xFF); } OF_HASH_FINALIZE(hash); return hash; } - (void)dealloc { OFObject **objs; size_t len, i; if (array != nil) { |
︙ | ︙ | |||
222 223 224 225 226 227 228 229 230 231 232 233 234 235 | } - addObject: (OFObject*)obj { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - removeNObjects: (size_t)nobjects { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } | > > > > > > < < < < < | < | < < | < < < < < | < | < | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | } - addObject: (OFObject*)obj { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - removeObjectAtIndex: (size_t)index { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - removeNObjects: (size_t)nobjects { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - removeNObjects: (size_t)nobjects atIndex: (size_t)index { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } @end |
Modified src/OFMutableArray.h from [04909fe688] to [e4a5edb3f5].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * Adds an object to the OFDataArray. * * \param obj An object to add */ - addObject: (OFObject*)obj; /** * Removes the specified amount of objects from the end of the OFDataArray. * * \param nobjects The number of objects to remove */ - removeNObjects: (size_t)nobjects; @end | > > > > > > > > > > > > > > > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /** * Adds an object to the OFDataArray. * * \param obj An object to add */ - addObject: (OFObject*)obj; /** * Removes the object at the specified index. * * \param index The index of the object to remove */ - removeObjectAtIndex: (size_t)index; /** * Removes the specified amount of objects from the end of the OFDataArray. * * \param nobjects The number of objects to remove */ - removeNObjects: (size_t)nobjects; /** * Removes the specified amount of objects at the specified index. * * \param nobjects The number of objects to remove * \param index The index at which the objects are removed */ - removeNObjects: (size_t)nitems atIndex: (size_t)index; @end |
Modified src/OFMutableArray.m from [1f2d4fefb4] to [c4806dc153].
︙ | ︙ | |||
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 | - addObject: (OFObject*)obj { [array addItem: &obj]; [obj retain]; return self; } - removeNObjects: (size_t)nobjects { OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = len - nobjects; i < len; i++) [objs[i] release]; [array removeNItems: nobjects]; return self; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | - addObject: (OFObject*)obj { [array addItem: &obj]; [obj retain]; return self; } - removeObjectAtIndex: (size_t)index { return [self removeNObjects: 1 atIndex: index]; } - removeNObjects: (size_t)nobjects { OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = len - nobjects; i < len; i++) [objs[i] release]; [array removeNItems: nobjects]; return self; } - removeNObjects: (size_t)nobjects atIndex: (size_t)index { OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = index; i < len && i < index + nobjects; i++) [objs[i] release]; [array removeNItems: nobjects atIndex: index]; return self; } @end |
Modified tests/OFArray.m from [fa2389e699] to [c96ae57ccf].
︙ | ︙ | |||
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | [[a[2] objectAtIndex: 0] isEqual: c_ary[0]] && [[a[2] objectAtIndex: 1] isEqual: c_ary[1]] && [[a[2] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[removeNObjects:]", [a[0] removeNObjects: 2] && [a[0] count] == 1 && [[a[0] objectAtIndex: 0] isEqual: c_ary[0]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1]) [pool release]; } | > > > > > > > > > | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | [[a[2] objectAtIndex: 0] isEqual: c_ary[0]] && [[a[2] objectAtIndex: 1] isEqual: c_ary[1]] && [[a[2] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[removeNObjects:]", [a[0] removeNObjects: 2] && [a[0] count] == 1 && [[a[0] objectAtIndex: 0] isEqual: c_ary[0]]) a[1] = [[a[1] mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", [a[1] removeObjectAtIndex: 1] && [a[1] count] == 2 && [[a[1] objectAtIndex: 1] isEqual: c_ary[2]]) a[2] = [[a[2] mutableCopy] autorelease]; TEST(@"-[removeNObjects:atIndex:]", [a[2] removeNObjects: 2 atIndex: 0] && [a[2] count] == 1 && [[a[2] objectAtIndex: 0] isEqual: c_ary[2]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1]) [pool release]; } |