Differences From Artifact [c77b46c66d]:
- File
src/OFDictionary_hashtable.m
— part of check-in
[f7576a66ce]
at
2012-06-06 13:47:52
on branch trunk
— Slightly change the memory management API.
Also fix a bug where OFBigDataArray would waste memory. (user: js, size: 17860) [annotate] [blame] [check-ins using] [more...]
To Artifact [81e5d7fd45]:
- File src/OFDictionary_hashtable.m — part of check-in [11d3d69a22] at 2012-06-10 13:28:05 on branch trunk — More API improvements. (user: js, size: 17811) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
77 78 79 80 81 82 83 | [OFMutableDictionary_hashtable class]]) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; hashtable = (OFDictionary_hashtable*)dictionary; | | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | [OFMutableDictionary_hashtable class]]) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; hashtable = (OFDictionary_hashtable*)dictionary; data = [self allocMemoryWithSize: sizeof(*data) count: hashtable->size]; for (i = 0; i < hashtable->size; i++) data[i] = NULL; size = hashtable->size; count = hashtable->count; |
︙ | ︙ | |||
137 138 139 140 141 142 143 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithSize: sizeof(*data) count: newSize]; for (i = 0; i < newSize; i++) data[i] = NULL; size = newSize; pool = [[OFAutoreleasePool alloc] init]; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | struct of_dictionary_hashtable_bucket *bucket; if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | struct of_dictionary_hashtable_bucket *bucket; if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; data = [self allocMemoryWithSize: sizeof(*data) count: 2]; size = 2; for (i = 0; i < size; i++) data[i] = NULL; i = [key hash] & 1; |
︙ | ︙ | |||
270 271 272 273 274 275 276 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithSize: sizeof(*data) count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; for (i = 0; i < count; i++) { |
︙ | ︙ | |||
391 392 393 394 395 396 397 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithSize: sizeof(*data) count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; /* Add first key / object pair */ |
︙ | ︙ | |||
644 645 646 647 648 649 650 | return NO; } - (OFArray*)allKeys { OFArray *ret; | | | | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | return NO; } - (OFArray*)allKeys { OFArray *ret; id *keys = [self allocMemoryWithSize: sizeof(*keys) count: count]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) keys[j++] = data[i]->key; assert(j == count); |
︙ | ︙ | |||
667 668 669 670 671 672 673 | return ret; } - (OFArray*)allObjects { OFArray *ret; | | | | 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | return ret; } - (OFArray*)allObjects { OFArray *ret; id *objects = [self allocMemoryWithSize: sizeof(*objects) count: count]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) objects[j++] = data[i]->object; assert(j == count); |
︙ | ︙ |