@@ -100,8 +100,8 @@ struct HNode *ets_hashtable_new_node(term entry, int keypos)
100
100
}
101
101
102
102
term new_entry = memory_copy_term_tree (& new_node -> heap , entry );
103
- TERM_DEBUG_ASSERT (term_is_tuple (new_entry ));
104
- TERM_DEBUG_ASSERT (term_get_tuple_arity (new_entry ) >= keypos );
103
+ assert (term_is_tuple (new_entry ));
104
+ assert (term_get_tuple_arity (new_entry ) >= keypos );
105
105
term key = term_get_tuple_element (new_entry , keypos );
106
106
107
107
new_node -> next = NULL ;
@@ -130,7 +130,12 @@ EtsHashtableErrorCode ets_hashtable_insert(struct EtsHashTable *hash_table, stru
130
130
struct HNode * node = hash_table -> buckets [index ];
131
131
struct HNode * last_node = NULL ;
132
132
while (node ) {
133
- if (term_compare (key , node -> key , TermCompareExact , global ) == TermEquals ) {
133
+ TermCompareResult cmp = term_compare (key , node -> key , TermCompareExact , global );
134
+ if (UNLIKELY (cmp == TermCompareMemoryAllocFail )) {
135
+ return EtsHashtableError ;
136
+ }
137
+
138
+ if (cmp == TermEquals ) {
134
139
if (opts & EtsHashtableAllowOverwrite ) {
135
140
if (IS_NULL_PTR (last_node )) {
136
141
new_node -> next = node -> next ;
@@ -142,7 +147,7 @@ EtsHashtableErrorCode ets_hashtable_insert(struct EtsHashTable *hash_table, stru
142
147
ets_hashtable_free_node (node , global );
143
148
return EtsHashtableOk ;
144
149
} else {
145
- return EtsHashtableFailure ;
150
+ return EtsHashtableKeyAlreadyExists ;
146
151
}
147
152
}
148
153
last_node = node ;
0 commit comments