Differences From Artifact [f9877d131a]:
- File src/runtime/hashtable.m — part of check-in [bc531024f5] at 2012-05-10 18:38:16 on branch runtime — Return objects as void* instead of const void*. (user: js, size: 3941) [annotate] [blame] [check-ins using] [more...]
To Artifact [3bc4ddb944]:
- File
src/runtime/hashtable.m
— part of check-in
[345eb93240]
at
2012-07-17 01:09:50
on branch trunk
— Rename ERROR() to OBJC_ERROR().
ERROR seems to be defined on MinGW32 and it's likely that it's also used
on other systems, thus it's better to prefix it with OBJC_. (user: js, size: 3981) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
48 49 50 51 52 53 54 | struct objc_hashtable* objc_hashtable_new(uint32_t size) { struct objc_hashtable *h; uint32_t i; if ((h = malloc(sizeof(struct objc_hashtable))) == NULL) | | | | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | struct objc_hashtable* objc_hashtable_new(uint32_t size) { struct objc_hashtable *h; uint32_t i; if ((h = malloc(sizeof(struct objc_hashtable))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table!"); h->count = 0; h->last_idx = size - 1; h->data = malloc(size * sizeof(struct objc_hashtable_bucket*)); if (h->data == NULL) OBJC_ERROR("Not enough memory to allocate hash table!"); for (i = 0; i < size; i++) h->data[i] = NULL; return h; } |
︙ | ︙ | |||
80 81 82 83 84 85 86 | struct objc_hashtable_bucket **ndata; uint32_t nsize = (h->last_idx + 1) << 1; assert(nsize > 0); ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*)); if (ndata == NULL) | | > | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | struct objc_hashtable_bucket **ndata; uint32_t nsize = (h->last_idx + 1) << 1; assert(nsize > 0); ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*)); if (ndata == NULL) OBJC_ERROR("Not enough memory to insert into hash " "table!"); for (i = 0; i < nsize; i++) ndata[i] = NULL; for (i = 0; i <= h->last_idx; i++) { if (h->data[i] != NULL) { uint32_t j; |
︙ | ︙ | |||
102 103 104 105 106 107 108 | last = h->data[i]->hash & (nsize - 1); for (j = 0; j < last && ndata[j] != NULL; j++); } if (j >= last) | | | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | last = h->data[i]->hash & (nsize - 1); for (j = 0; j < last && ndata[j] != NULL; j++); } if (j >= last) OBJC_ERROR("No free bucket!"); ndata[j] = h->data[i]; } } free(h->data); h->data = ndata; |
︙ | ︙ | |||
124 125 126 127 128 129 130 | if (i >= last) { last = hash & h->last_idx; for (i = 0; i < last && h->data[i] != NULL; i++); } if (i >= last) | | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | if (i >= last) { last = hash & h->last_idx; for (i = 0; i < last && h->data[i] != NULL; i++); } if (i >= last) OBJC_ERROR("No free bucket!"); if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table bucket!"); bucket->key = key; bucket->hash = hash; bucket->obj = obj; h->data[i] = bucket; h->count++; |
︙ | ︙ |