Differences From Artifact [66616ef22a]:
- File
src/OFArray_adjacent.m
— part of check-in
[2a27cf3000]
at
2016-01-03 00:41:26
on branch trunk
— Update copyright
While at it, also update the mail address. (user: js, size: 6993) [annotate] [blame] [check-ins using]
To Artifact [b1e29fe508]:
- File src/OFArray_adjacent.m — part of check-in [e0b9167693] at 2016-02-21 15:37:42 on branch trunk — Make use of C99-style for loops (user: js, size: 7021) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
84 85 86 87 88 89 90 | return self; } - initWithArray: (OFArray*)array { id const *objects; | | | | < | < < | | 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 155 156 157 158 | return self; } - initWithArray: (OFArray*)array { id const *objects; size_t count; self = [super init]; if (array == nil) return self; @try { objects = [array objects]; count = [array count]; _array = [[OFDataArray alloc] initWithItemSize: sizeof(id) capacity: count]; } @catch (id e) { [self release]; @throw e; } @try { for (size_t i = 0; i < count; i++) [objects[i] retain]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ [_array release]; _array = nil; [self release]; @throw e; } return self; } - initWithObjects: (id const*)objects count: (size_t)count { self = [self init]; @try { bool ok = true; for (size_t i = 0; i < count; i++) { if (objects[i] == nil) ok = false; [objects[i] retain]; } if (!ok) @throw [OFInvalidArgumentException exception]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; [self release]; @throw e; } return self; |
︙ | ︙ | |||
214 215 216 217 218 219 220 | return *((id*)[_array itemAtIndex: index]); } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { id *objects = [_array items]; | | | | | | | | 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | return *((id*)[_array itemAtIndex: index]); } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { id *objects = [_array items]; size_t count = [_array count]; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exception]; for (size_t i = 0; i < range.length; i++) buffer[i] = objects[range.location + i]; } - (size_t)indexOfObject: (id)object { id *objects; size_t count; if (object == nil) return OF_NOT_FOUND; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) if ([objects[i] isEqual: object]) return i; return OF_NOT_FOUND; } - (size_t)indexOfObjectIdenticalTo: (id)object { id *objects; size_t count; if (object == nil) return OF_NOT_FOUND; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) if (objects[i] == object) return i; return OF_NOT_FOUND; } |
︙ | ︙ | |||
280 281 282 283 284 285 286 | range: range]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; | | | | | | 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 322 | range: range]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; size_t count; if (![object isKindOfClass: [OFArray_adjacent class]] && ![object isKindOfClass: [OFMutableArray_adjacent class]]) return [super isEqual: object]; otherArray = object; count = [_array count]; if (count != [otherArray count]) return false; objects = [_array items]; otherObjects = [otherArray objects]; for (size_t i = 0; i < count; i++) if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } - (uint32_t)hash { id *objects = [_array items]; size_t count = [_array count]; uint32_t hash; OF_HASH_INIT(hash); for (size_t i = 0; i < count; i++) OF_HASH_ADD_HASH(hash, [objects[i] hash]); OF_HASH_FINALIZE(hash); return hash; } |
︙ | ︙ | |||
348 349 350 351 352 353 354 | return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; | | | | | | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; size_t count = [_array count]; bool stop = false; for (size_t i = 0; i < count && !stop; i++) block(objects[i], i, &stop); } #endif - (void)dealloc { id *objects = [_array items]; size_t count = [_array count]; for (size_t i = 0; i < count; i++) [objects[i] release]; [_array release]; [super dealloc]; } @end |