Differences From Artifact [dc60bfa33c]:
- File
src/OFDictionary_hashtable.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: 17572) [annotate] [blame] [check-ins using]
To Artifact [fd15d2ff3e]:
- File src/OFDictionary_hashtable.m — part of check-in [d42a56787b] at 2012-03-12 12:14:32 on branch trunk — Add +[OFDictionary dictionaryWithObjects:forKeys:count:]. (user: js, size: 17804) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
231 232 233 234 235 236 237 238 239 240 | return self; } - initWithObjects: (OFArray*)objects forKeys: (OFArray*)keys { self = [super init]; @try { | > > > > > > > > > > > > > > > > > > > > > > < < < | | 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 265 266 267 268 269 270 271 272 | return self; } - initWithObjects: (OFArray*)objects forKeys: (OFArray*)keys { id ret; @try { if ([objects count] != [keys count]) @throw [OFInvalidArgumentException exceptionWithClass: isa]; ret = [self initWithObjects: [objects objects] forKeys: [keys objects] count: [objects count]]; } @catch (id e) { [self release]; @throw e; } return ret; } - initWithObjects: (id*)objects forKeys: (id*)keys count: (size_t)count_ { self = [super init]; @try { uint32_t i, j, newSize; count = count_; if (count > UINT32_MAX) @throw [OFOutOfRangeException exceptionWithClass: isa]; for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; |
︙ | ︙ | |||
262 263 264 265 266 267 268 | data[j] = NULL; size = newSize; for (i = 0; i < count; i++) { uint32_t hash, last; | | | | < | | 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 | data[j] = NULL; size = newSize; for (i = 0; i < count; i++) { uint32_t hash, last; hash = [keys[i] hash]; last = size; for (j = hash & (size - 1); j < last && data[j] != NULL; j++) if ([data[j]->key isEqual: keys[i]]) break; /* In case the last bucket is already used */ if (j >= last) { last = hash & (size - 1); for (j = 0; j < last && data[j] != NULL; j++) if ([data[j]->key isEqual: keys[i]]) break; } /* Key not in dictionary */ if (j >= last || data[j] == NULL || ![data[j]->key isEqual: keys[i]]) { struct of_dictionary_hashtable_bucket *bucket; id key; last = size; j = hash & (size - 1); for (; j < last && data[j] != NULL; j++); |
︙ | ︙ | |||
305 306 307 308 309 310 311 | if (j >= last) @throw [OFOutOfRangeException exceptionWithClass: isa]; bucket = [self allocMemoryWithSize: sizeof(*bucket)]; | | | | | | 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 | if (j >= last) @throw [OFOutOfRangeException exceptionWithClass: isa]; bucket = [self allocMemoryWithSize: sizeof(*bucket)]; key = [keys[i] copy]; bucket->key = key; bucket->object = [objects[i] retain]; bucket->hash = hash; data[j] = bucket; continue; } /* * The key is already in the dictionary. However, we * just replace it so that the programmer gets the same * behavior as if he'd call setObject:forKey: for each * key/object pair. */ [objects[i] retain]; [data[j]->object release]; data[j]->object = objects[i]; } } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ |