improve object_hash

This commit is contained in:
lixianjing 2024-08-22 17:40:16 +08:00
parent e4519e0bf2
commit 5701b74fb8
2 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,7 @@
* 完善 object_hash 测试 (感谢兆坤提供补丁)
* 修复 object_clone (感谢兆坤提供补丁)
* 完善注释(感谢兆坤提供补丁)
* 完善object_hash(感谢兆坤提供补丁)
2024/08/21
* release 1.8

View File

@ -382,13 +382,11 @@ ret_t object_hash_set_keep_prop_type(tk_object_t* obj, bool_t keep_prop_type) {
return RET_OK;
}
ret_t object_hash_set_hash_base(tk_object_t* obj, uint64_t base) {
static ret_t object_hash_update_props_hash(tk_object_t* obj) {
object_hash_t* o = OBJECT_HASH(obj);
uint32_t i = 0;
return_value_if_fail(o != NULL, RET_BAD_PARAMS);
o->hash_base = base;
for (i = 0; i < o->props.size; i++) {
named_value_hash_t* iter = (named_value_hash_t*)(o->props.elms[i]);
iter->hash = named_value_hash_get_hash_from_str(iter->base.name, o->hash_base);
@ -398,6 +396,18 @@ ret_t object_hash_set_hash_base(tk_object_t* obj, uint64_t base) {
return RET_OK;
}
ret_t object_hash_set_hash_base(tk_object_t* obj, uint64_t base) {
object_hash_t* o = OBJECT_HASH(obj);
return_value_if_fail(o != NULL, RET_BAD_PARAMS);
if (o->hash_base != base) {
o->hash_base = base;
object_hash_update_props_hash(obj);
}
return RET_OK;
}
object_hash_t* object_hash_cast(tk_object_t* obj) {
return_value_if_fail(obj != NULL && obj->vt == &s_object_hash_vtable, NULL);
return (object_hash_t*)(obj);