Differences From Artifact [e861c4b211]:
- File src/OFMapTable.m — part of check-in [8a194de51c] at 2013-05-04 10:05:50 on branch trunk — OFMapTable: Minor corrections. (user: js, size: 16124) [annotate] [blame] [check-ins using]
To Artifact [40dcf1c644]:
- File
src/OFMapTable.m
— part of check-in
[3d16a30f41]
at
2013-06-22 12:12:36
on branch trunk
— Rework exceptions.
This mostly removes the argument for the class in which the exception
occurred. As backtraces were recently added for all platforms, the
passed class does not give any extra information on where the exception
occurred anymore.This also removes a few other arguments which were not too helpful. In
the past, the idea was to pass as many arguments as possible so that it
is easier to find the origin of the exception. However, as backtraces
are a much better way to find the origin, those are not useful anymore
and just make the exception more cumbersome to use. The rule is now to
only pass arguments that might help in recovering from the exception or
provide information that is otherwise not easily accessible. (user: js, size: 15634) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
133 134 135 136 137 138 139 | SET_DEFAULT(_valueFunctions.equal, default_equal); #undef SET_DEFAULT if (capacity > UINT32_MAX || capacity > UINT32_MAX / sizeof(*_buckets) || capacity > UINT32_MAX / 8) | | < | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | SET_DEFAULT(_valueFunctions.equal, default_equal); #undef SET_DEFAULT if (capacity > UINT32_MAX || capacity > UINT32_MAX / sizeof(*_buckets) || capacity > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; for (_capacity = 1; _capacity < capacity; _capacity *= 2); if (capacity * 8 / _capacity >= 6) _capacity *= 2; if (_capacity < MIN_CAPACITY) _capacity = MIN_CAPACITY; |
︙ | ︙ | |||
253 254 255 256 257 258 259 | } - (void*)valueForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) | | < < | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | } - (void*)valueForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deleted) continue; |
︙ | ︙ | |||
292 293 294 295 296 297 298 | - (void)OF_resizeForCount: (uint32_t)count { uint32_t i, fullness, capacity; struct of_map_table_bucket **buckets; if (count > UINT32_MAX || count > UINT32_MAX / sizeof(*_buckets) || count > UINT32_MAX / 8) | | | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | - (void)OF_resizeForCount: (uint32_t)count { uint32_t i, fullness, capacity; struct of_map_table_bucket **buckets; if (count > UINT32_MAX || count > UINT32_MAX / sizeof(*_buckets) || count > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / _capacity; if (fullness >= 6) capacity = _capacity * 2; else if (fullness <= 1) capacity = _capacity / 2; |
︙ | ︙ | |||
351 352 353 354 355 356 357 | forKey: (void*)key hash: (uint32_t)hash { uint32_t i, last; void *old; if (key == NULL || value == NULL) | | < < | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | forKey: (void*)key hash: (uint32_t)hash { uint32_t i, last; void *old; if (key == NULL || value == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(hash, _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deleted) continue; |
︙ | ︙ | |||
401 402 403 404 405 406 407 | last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL && _buckets[i] != &deleted; i++); } if (i >= last) | | < | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL && _buckets[i] != &deleted; i++); } if (i >= last) @throw [OFOutOfRangeException exception]; bucket = [self allocMemoryWithSize: sizeof(*bucket)]; @try { bucket->key = _keyFunctions.retain(key); } @catch (id e) { [self freeMemory: bucket]; |
︙ | ︙ | |||
447 448 449 450 451 452 453 | } - (void)removeValueForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) | | < < | 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | } - (void)removeValueForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deleted) continue; |
︙ | ︙ | |||
583 584 585 586 587 588 589 | size_t i; bool stop = false; unsigned long mutations = _mutations; for (i = 0; i < _capacity && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException | < | < | | < < | 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | size_t i; bool stop = false; unsigned long mutations = _mutations; for (i = 0; i < _capacity && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) block(_buckets[i]->key, _buckets[i]->value, &stop); } } - (void)replaceValuesUsingBlock: (of_map_table_replace_block_t)block { size_t i; unsigned long mutations = _mutations; for (i = 0; i < _capacity; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *new; new = block(_buckets[i]->key, _buckets[i]->value); if (new == NULL) @throw [OFInvalidArgumentException exception]; if (new != _buckets[i]->value) { _valueFunctions.release(_buckets[i]->value); _buckets[i]->value = _valueFunctions.retain(new); } } |
︙ | ︙ | |||
678 679 680 681 682 683 684 | abort(); } - (void)reset { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException | < | < | < | | 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | abort(); } - (void)reset { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; _position = 0; } @end @implementation OFMapTableKeyEnumerator - (void*)nextValue { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deleted); _position++); if (_position < _capacity) return _buckets[_position++]->key; else return NULL; } @end @implementation OFMapTableValueEnumerator - (void*)nextValue { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deleted); _position++); if (_position < _capacity) return _buckets[_position++]->value; else |
︙ | ︙ | |||
749 750 751 752 753 754 755 | { id ret; @try { ret = [_enumerator nextValue]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException | < | < | | 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | { id ret; @try { ret = [_enumerator nextValue]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: _object]; } return ret; } - (void)reset { @try { [_enumerator reset]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: _object]; } } @end |