Comment: | Revert several OFHashMap related commits.
This reverts: It turned out that these were slowing down all classes based on |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6712442fad3b6214a6292b266b0318db |
User & Date: | js on 2012-12-07 13:57:13 |
Other Links: | manifest | tags |
2012-12-07
| ||
14:50 | quicksort: Reduce used space. check-in: a747ad5478 user: js tags: trunk | |
13:57 | Revert several OFHashMap related commits. check-in: 6712442fad user: js tags: trunk | |
02:11 | Make GCC happy by declaring private methods. check-in: bff1f8e5a7 user: js tags: trunk | |
Modified src/OFMapTable.h from [91b9317d21] to [dcccbffbc5].
︙ | ︙ | |||
46 47 48 49 50 51 52 | */ @interface OFMapTable: OFObject <OFCopying, OFFastEnumeration> { of_map_table_functions_t keyFunctions, valueFunctions; struct of_map_table_bucket **buckets; uint32_t minCapacity, capacity, count; unsigned long mutations; | < < | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | */ @interface OFMapTable: OFObject <OFCopying, OFFastEnumeration> { of_map_table_functions_t keyFunctions, valueFunctions; struct of_map_table_bucket **buckets; uint32_t minCapacity, capacity, count; unsigned long mutations; } /*! * @brief Creates a new OFMapTable with the specified key and value functions. * * @param keyFunctions A structure of functions for handling keys * @param valueFunctions A structure of functions for handling values |
︙ | ︙ |
Modified src/OFMapTable.m from [fda4d04529] to [458807374d].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #include <assert.h> #import "OFMapTable.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" |
︙ | ︙ | |||
148 149 150 151 152 153 154 | minCapacity = capacity; buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); | < < < < < | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | minCapacity = capacity; buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
230 231 232 233 234 235 236 | @try { uint32_t i; for (i = 0; i < capacity; i++) if (buckets[i] != NULL && buckets[i] != &deleted) [copy OF_setValue: buckets[i]->value forKey: buckets[i]->key | < | < | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | @try { uint32_t i; for (i = 0; i < capacity; i++) if (buckets[i] != NULL && buckets[i] != &deleted) [copy OF_setValue: buckets[i]->value forKey: buckets[i]->key hash: buckets[i]->hash]; } @catch (id e) { [copy release]; @throw e; } copy->minCapacity = MIN_CAPACITY; |
︙ | ︙ | |||
257 258 259 260 261 262 263 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; hash = keyFunctions.hash(key); last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) |
︙ | ︙ | |||
287 288 289 290 291 292 293 | } return NULL; } - (void)OF_resizeForCount: (uint32_t)newCount { | | < | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | } return NULL; } - (void)OF_resizeForCount: (uint32_t)newCount { uint32_t i, fullness, newCapacity; struct of_map_table_bucket **newBuckets; if (newCount > UINT32_MAX || newCount > UINT32_MAX / sizeof(*buckets) || newCount > UINT32_MAX / 8) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; fullness = newCount * 8 / capacity; |
︙ | ︙ | |||
313 314 315 316 317 318 319 | newBuckets = [self allocMemoryWithSize: sizeof(*newBuckets) count: newCapacity]; for (i = 0; i < newCapacity; i++) newBuckets[i] = NULL; | < < < < < < < < < < < | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | newBuckets = [self allocMemoryWithSize: sizeof(*newBuckets) count: newCapacity]; for (i = 0; i < newCapacity; i++) newBuckets[i] = NULL; for (i = 0; i < capacity; i++) { if (buckets[i] != NULL && buckets[i] != &deleted) { uint32_t j, last; last = newCapacity; j = buckets[i]->hash & (newCapacity - 1); for (; j < last && newBuckets[j] != NULL; j++); /* In case the last bucket is already used */ if (j >= last) { |
︙ | ︙ | |||
350 351 352 353 354 355 356 | newBuckets[j] = buckets[i]; } } [self freeMemory: buckets]; buckets = newBuckets; capacity = newCapacity; | < < | < | < | < | | | 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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | newBuckets[j] = buckets[i]; } } [self freeMemory: buckets]; buckets = newBuckets; capacity = newCapacity; } - (void)OF_setValue: (void*)value forKey: (void*)key hash: (uint32_t)hash { uint32_t i, last; void *old; if (key == NULL || value == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) break; } /* In case the last bucket is already used */ if (i >= last) { last = hash & (capacity - 1); for (i = 0; i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) break; } } /* Key not in dictionary */ if (i >= last || buckets[i] == NULL || buckets[i] == &deleted || !keyFunctions.equal(buckets[i]->key, key)) { struct of_map_table_bucket *bucket; [self OF_resizeForCount: count + 1]; mutations++; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL && buckets[i] != &deleted; i++); /* In case the last bucket is already used */ if (i >= last) { last = hash & (capacity - 1); for (i = 0; i < last && buckets[i] != NULL && buckets[i] != &deleted; i++); } if (i >= last) @throw [OFOutOfRangeException |
︙ | ︙ | |||
434 435 436 437 438 439 440 | bucket->value = valueFunctions.retain(value); } @catch (id e) { keyFunctions.release(key); [self freeMemory: bucket]; @throw e; } | | | 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | bucket->value = valueFunctions.retain(value); } @catch (id e) { keyFunctions.release(key); [self freeMemory: bucket]; @throw e; } bucket->hash = hash; buckets[i] = bucket; count++; return; } |
︙ | ︙ | |||
464 465 466 467 468 469 470 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | | | 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; hash = keyFunctions.hash(key); last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) { |
︙ | ︙ |
Modified src/OFObject.h from [b44a7c59ae] to [c663f1ca8f].
︙ | ︙ | |||
873 874 875 876 877 878 879 | #import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment, void **extra); | < | 873 874 875 876 877 878 879 880 881 882 883 884 885 | #import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment, void **extra); extern size_t of_pagesize; extern size_t of_num_cpus; extern uint32_t of_hash_seed; #ifdef __cplusplus } #endif |
Modified src/OFObject.m from [0307a15aa9] to [ce3e8ba58d].
︙ | ︙ | |||
225 226 227 228 229 230 231 | if OF_UNLIKELY (extra != NULL) *extra = (char*)instance + instanceSize + extraAlignment; return instance; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | if OF_UNLIKELY (extra != NULL) *extra = (char*)instance + instanceSize + extraAlignment; return instance; } const char* _NSPrintForDebugger(id object) { return [[object description] cStringWithEncoding: OF_STRING_ENCODING_NATIVE]; } |
︙ | ︙ | |||
307 308 309 310 311 312 313 | of_pagesize = 4096; # ifdef _SC_NPROCESSORS_CONF if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1) # endif of_num_cpus = 1; #endif | > | > > > > > > > > > > > | 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 | of_pagesize = 4096; # ifdef _SC_NPROCESSORS_CONF if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1) # endif of_num_cpus = 1; #endif #if defined(OF_HAVE_ARC4RANDOM) of_hash_seed = arc4random(); #elif defined(OF_HAVE_RANDOM) struct timeval t; gettimeofday(&t, NULL); srandom((unsigned)(t.tv_sec ^ t.tv_usec)); of_hash_seed = (uint32_t)((random() << 16) | (random() & 0xFFFF)); #else struct timeval t; gettimeofday(&t, NULL); srand((unsigned)(t.tv_sec ^ t.tv_usec)); of_hash_seed = (uint32_t)((rand() << 16) | (rand() & 0xFFFF)); #endif } + (void)initialize { } + alloc |
︙ | ︙ |
Modified src/macros.h from [6b2bc955be] to [ba733f14be].
︙ | ︙ | |||
321 322 323 324 325 326 327 | #if defined(__MACH__) && defined(__arm__) # define OF_IOS #endif #define OF_ROL(value, bits) \ (((value) << ((bits) % (sizeof(value) * 8))) | \ (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) | < < < | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | #if defined(__MACH__) && defined(__arm__) # define OF_IOS #endif #define OF_ROL(value, bits) \ (((value) << ((bits) % (sizeof(value) * 8))) | \ (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) #define OF_HASH_INIT(hash) hash = of_hash_seed #define OF_HASH_ADD(hash, byte) \ { \ hash += (uint8_t)(byte); \ hash += (hash << 10); \ hash ^= (hash >> 6); \ |
︙ | ︙ |