From 239704c38c79be57b08577c12ef8768091ba1248 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Thu, 22 Aug 2024 17:37:43 +0800 Subject: [PATCH] improve object clone --- docs/changes.md | 1 + src/tkc/object_default.c | 5 +++++ src/tkc/object_hash.c | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 55a84868f..14a4f012f 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -3,6 +3,7 @@ 2024/08/22 * 解决 object_hash 冲突问题(感谢兆坤提供补丁) * 完善 object_hash 测试 (感谢兆坤提供补丁) + * 修复 object_clone (感谢兆坤提供补丁) 2024/08/21 * release 1.8 diff --git a/src/tkc/object_default.c b/src/tkc/object_default.c index 89011c436..738538f41 100644 --- a/src/tkc/object_default.c +++ b/src/tkc/object_default.c @@ -339,6 +339,11 @@ tk_object_t* object_default_clone(object_default_t* o) { return_value_if_fail(dup != NULL, NULL); dupo = OBJECT_DEFAULT(dup); + + dupo->enable_path = o->enable_path; + dupo->keep_prop_type = o->keep_prop_type; + dupo->name_case_insensitive = o->name_case_insensitive; + for (i = 0; i < o->props.size; i++) { named_value_t* iter = (named_value_t*)(o->props.elms[i]); named_value_t* nv = named_value_create_ex(iter->name, &(iter->value)); diff --git a/src/tkc/object_hash.c b/src/tkc/object_hash.c index 190d23c49..85bd27f24 100644 --- a/src/tkc/object_hash.c +++ b/src/tkc/object_hash.c @@ -54,8 +54,8 @@ static int32_t object_hash_find_prop_index_by_name(tk_object_t* obj, const char* (void*)hash, &bucket)) { named_value_hash_t* right_nvh = NULL; darray_sort(&bucket, (tk_compare_t)named_value_compare); - right_nvh = - darray_bsearch(&bucket, (tk_compare_t)named_value_compare_by_name, (void*)name); + right_nvh = (named_value_hash_t*)darray_bsearch( + &bucket, (tk_compare_t)named_value_compare_by_name, (void*)name); if (right_nvh != NULL) { ret = darray_find_index_ex(&o->props, pointer_compare, (void*)right_nvh); } @@ -355,6 +355,11 @@ tk_object_t* object_hash_clone(object_hash_t* o) { return_value_if_fail(dup != NULL, NULL); dupo = OBJECT_HASH(dup); + + dupo->hash_base = o->hash_base; + dupo->enable_path = o->enable_path; + dupo->keep_prop_type = o->keep_prop_type; + for (i = 0; i < o->props.size; i++) { named_value_hash_t* iter = (named_value_hash_t*)(o->props.elms[i]); named_value_hash_t* nvh = named_value_hash_clone(iter);