Skip to content

Commit

Permalink
Merge pull request #369 from tDwtp/move-hash
Browse files Browse the repository at this point in the history
move hash functionality
  • Loading branch information
marcobambini authored Jun 28, 2021
2 parents 7322fc2 + 6b31817 commit 67c95a5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
30 changes: 30 additions & 0 deletions src/shared/gravity_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,33 @@ bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable

return result;
}

void gravity_hash_finteralfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, key, data)
if (gravity_value_isobject(value)) {
gravity_object_t *obj = VALUE_AS_OBJECT(value);
if (OBJECT_ISA_CLOSURE(obj)) {
gravity_closure_t *closure = (gravity_closure_t *)obj;
if (closure->f && closure->f->tag == EXEC_TYPE_INTERNAL) gravity_function_free(NULL, closure->f);
}
}
}

void gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, value)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, key);
}

void gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, key);
gravity_value_free(vm, value);
}

void gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, key)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, value);
}
7 changes: 7 additions & 0 deletions src/shared/gravity_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ GRAVITY_API void gravity_hash_transform (gravity_hash_t *hashtable,

GRAVITY_API bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable2, gravity_hash_compare_fn compare, void *data);

// MARK: - CALLBACKS -
// HASH FREE CALLBACK FUNCTION
GRAVITY_API void gravity_hash_finteralfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 0 additions & 30 deletions src/shared/gravity_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,6 @@ static void gravity_hash_serialize (gravity_hash_t *table, gravity_value_t key,
assert(0);
}

void gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, key);
gravity_value_free(vm, value);
}

void gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, value)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, key);
}

void gravity_hash_finteralfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, key, data)
if (gravity_value_isobject(value)) {
gravity_object_t *obj = VALUE_AS_OBJECT(value);
if (OBJECT_ISA_CLOSURE(obj)) {
gravity_closure_t *closure = (gravity_closure_t *)obj;
if (closure->f && closure->f->tag == EXEC_TYPE_INTERNAL) gravity_function_free(NULL, closure->f);
}
}
}

void gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data) {
#pragma unused(table, key)
gravity_vm *vm = (gravity_vm *)data;
gravity_value_free(vm, value);
}

static void gravity_hash_internalsize (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data1, void *data2) {
#pragma unused(table)
uint32_t *size = (uint32_t *)data1;
Expand Down
7 changes: 0 additions & 7 deletions src/shared/gravity_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,6 @@ GRAVITY_API void gravity_string_set(gravity_string_t *obj, char *
GRAVITY_API uint32_t gravity_string_size (gravity_vm *vm, gravity_string_t *string);
GRAVITY_API gravity_value_t gravity_string_to_value (gravity_vm *vm, const char *s, uint32_t len);

// MARK: - CALLBACKS -
// HASH FREE CALLBACK FUNCTION
GRAVITY_API void gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_finteralfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
GRAVITY_API void gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 67c95a5

Please sign in to comment.