summaryrefslogtreecommitdiff
path: root/core/hash_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/hash_map.h')
-rw-r--r--core/hash_map.h30
1 files changed, 18 insertions, 12 deletions
diff --git a/core/hash_map.h b/core/hash_map.h
index 44459a3080..1513d7a65b 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -162,20 +162,21 @@ private:
new_hash_table[i] = 0;
}
- for (int i = 0; i < (1 << hash_table_power); i++) {
+ if (hash_table) {
+ for (int i = 0; i < (1 << hash_table_power); i++) {
- while (hash_table[i]) {
+ while (hash_table[i]) {
- Element *se = hash_table[i];
- hash_table[i] = se->next;
- int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
- se->next = new_hash_table[new_pos];
- new_hash_table[new_pos] = se;
+ Element *se = hash_table[i];
+ hash_table[i] = se->next;
+ int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
+ se->next = new_hash_table[new_pos];
+ new_hash_table[new_pos] = se;
+ }
}
- }
- if (hash_table)
memdelete_arr(hash_table);
+ }
hash_table = new_hash_table;
hash_table_power = new_hash_table_power;
}
@@ -207,7 +208,10 @@ private:
/* if element doesn't exist, create it */
Element *e = memnew(Element);
- ERR_FAIL_COND_V(!e, NULL); /* out of memory */
+ if (!e) {
+ ERR_EXPLAIN("Out of memory");
+ ERR_FAIL_V(NULL);
+ }
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
e->next = hash_table[index];
@@ -494,8 +498,10 @@ public:
} else { /* get the next key */
const Element *e = get_element(*p_key);
- ERR_FAIL_COND_V(!e, NULL); /* invalid key supplied */
-
+ if (!e) {
+ ERR_EXPLAIN("Invalid key supplied")
+ ERR_FAIL_V(NULL);
+ }
if (e->next) {
/* if there is a "next" in the list, return that */
return &e->next->pair.key;