Overview
Comment: | Add -[addNItems:fromCArray:atIndex:] to OFDataArray. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
806550f7eda938bda061a78e458758f5 |
User & Date: | js on 2009-12-02 09:29:24 |
Other Links: | manifest | tags |
Context
2009-12-02
| ||
09:38 | Add -[addObject:atIndex:] to OFArray. check-in: 806b5b24db user: js tags: trunk | |
09:29 | Add -[addNItems:fromCArray:atIndex:] to OFDataArray. check-in: 806550f7ed user: js tags: trunk | |
2009-12-01
| ||
17:45 | Fix -[removeItemAtIndex:], -[removeNItems:atIndex:], -[removeObject:]. check-in: b83a3b4d9c user: js tags: trunk | |
Changes
Modified src/OFDataArray.h from [f95fb1a241] to [8c7292e6d0].
︙ | ︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | /** * Adds an item to the OFDataArray. * * \param item A pointer to an arbitrary item */ - addItem: (void*)item; /** * Adds items from a C array to the OFDataArray. * * \param nitems The number of items to add * \param carray A C array containing the items to add */ - addNItems: (size_t)nitems fromCArray: (void*)carray; /** * Removes the item at the specified index. * * \param index The index of the item to remove */ - removeItemAtIndex: (size_t)index; | > > > > > > > > > > > > > > > > > > > > | 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 | /** * Adds an item to the OFDataArray. * * \param item A pointer to an arbitrary item */ - addItem: (void*)item; /** * Adds an item to the OFDataArray at the specified index. * * \param item A pointer to an arbitrary item * \param index The index where the item should be added */ - addItem: (void*)item atIndex: (size_t)index; /** * Adds items from a C array to the OFDataArray. * * \param nitems The number of items to add * \param carray A C array containing the items to add */ - addNItems: (size_t)nitems fromCArray: (void*)carray; /** * Adds items from a C array to the OFDataArray at the specified index. * * \param nitems The number of items to add * \param carray A C array containing the items to add * \param index The index where the items should be added */ - addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index; /** * Removes the item at the specified index. * * \param index The index of the item to remove */ - removeItemAtIndex: (size_t)index; |
︙ | ︙ |
Modified src/OFDataArray.m from [229b2dc05e] to [f8e71178db].
︙ | ︙ | |||
101 102 103 104 105 106 107 | if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + 1 withSize: itemsize]; | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 155 156 157 158 159 160 | if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + 1 withSize: itemsize]; memcpy(data + count * itemsize, item, itemsize); count++; return self; } - addItem: (void*)item atIndex: (size_t)index { return [self addNItems: 1 fromCArray: item atIndex: index]; } - addNItems: (size_t)nitems fromCArray: (void*)carray { if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nitems withSize: itemsize]; memcpy(data + count * itemsize, carray, nitems * itemsize); count += nitems; return self; } - addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index { if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nitems withSize: itemsize]; memmove(data + (index + nitems) * itemsize, data + index * itemsize, (count - index) * itemsize); memcpy(data + index * itemsize, carray, nitems * itemsize); count += nitems; return self; } - removeItemAtIndex: (size_t)index { |
︙ | ︙ | |||
266 267 268 269 270 271 272 | nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 353 354 355 356 357 358 359 | nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; memcpy(data + count * itemsize, item, itemsize); count++; size = nsize; return self; } - addNItems: (size_t)nitems fromCArray: (void*)carray { size_t nsize; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; memcpy(data + count * itemsize, carray, nitems * itemsize); count += nitems; size = nsize; return self; } - addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index { size_t nsize; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toNItems: nsize withSize: itemsize]; memmove(data + (index + nitems) * itemsize, data + index * itemsize, (count - index) * itemsize); memcpy(data + index * itemsize, carray, nitems * itemsize); count += nitems; size = nsize; return self; } - removeNItems: (size_t)nitems |
︙ | ︙ |
Modified tests/OFDataArray.m from [8dcec7e9e3] to [7e51a1f773].
︙ | ︙ | |||
82 83 84 85 86 87 88 | [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) TEST(@"-[removeNItems:atIndex:]", [array[0] removeNItems: 2 atIndex: 1] && [array[0] count] == 3 && !memcmp([array[0] cArray], "ade", 3)) | > > | > > > | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) TEST(@"-[removeNItems:atIndex:]", [array[0] removeNItems: 2 atIndex: 1] && [array[0] count] == 3 && !memcmp([array[0] cArray], "ade", 3)) TEST(@"-[addNItems:atIndex:]", [array[0] addNItems: 2 fromCArray: "bc" atIndex: 1] && [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) TEST(@"Building strings", (array[0] = [class dataArrayWithItemSize: 1]) && [array[0] addNItems: 6 fromCArray: (void*)str] && [array[0] addItem: ""] && !strcmp([array[0] cArray], str)) |
︙ | ︙ |