Differences From Artifact [f7f4dd215e]:
- File
src/runtime/sparsearray.m
— part of check-in
[d3158d091f]
at
2016-01-05 22:00:03
on branch trunk
— (u)int_fast*_t -> (u)int*_t
(U)INT_FAST*_MAX is broken on Android, which makes (u)int_fast*_t
dangerous to use while it does not provide any real speed benefit. (user: js, size: 2450) [annotate] [blame] [check-ins using]
To Artifact [ec11c93501]:
- File src/runtime/sparsearray.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: 2442) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
38 39 40 41 42 43 44 | return sparsearray; } void* objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; | < | < | < < | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | return sparsearray; } void* objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->index_size - 1; i++) { uintptr_t j = (idx >> ((sparsearray->index_size - i - 1) * 8)) & 0xFF; if ((iter = iter->next[j]) == NULL) return NULL; } return iter->next[idx & 0xFF]; } void objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx, void *value) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->index_size - 1; i++) { uintptr_t j = (idx >> ((sparsearray->index_size - i - 1) * 8)) & 0xFF; if (iter->next[j] == NULL) if ((iter->next[j] = calloc(1, sizeof(struct objc_sparsearray_data))) == NULL) OBJC_ERROR("Failed to allocate memory for " "sparse array!"); iter = iter->next[j]; } iter->next[idx & 0xFF] = value; } static void free_sparsearray_data(struct objc_sparsearray_data *data, uint8_t depth) { if (data == NULL || depth == 0) return; for (uint_fast16_t i = 0; i < 256; i++) free_sparsearray_data(data->next[i], depth - 1); free(data); } void objc_sparsearray_free(struct objc_sparsearray *sparsearray) { free_sparsearray_data(sparsearray->data, sparsearray->index_size); free(sparsearray); } |