From 8046e91439692d107e1b0bdcad08182251911c91 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Thu, 7 Nov 2024 16:38:41 +0800 Subject: [PATCH] improve object_array --- docs/changes.md | 1 + src/tkc/object_array.c | 4 ++-- tests/object_array_test.cc | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index c61cb42ca..632f00d2a 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -3,6 +3,7 @@ 2024/11/07 * 修复locale_infos_unref接口释放info对象无法清除assets_manager上的野指针导致崩溃的问题(感谢雨欣提供补丁) * 完善object_hash(感谢兆坤提供补丁) + * 完善object_array(感谢兆坤提供补丁) * 统一是否可从名字中获取index的判断逻辑(感谢兆坤提供补丁) 2024/11/06 diff --git a/src/tkc/object_array.c b/src/tkc/object_array.c index 3b472c539..31291fd1d 100644 --- a/src/tkc/object_array.c +++ b/src/tkc/object_array.c @@ -400,7 +400,7 @@ static ret_t object_array_find_props(tk_object_t* obj, tk_compare_t cmp, const v value_t* iter = &o->props[i]; tk_snprintf(name, TK_NAME_LEN, "%" PRIu32, i); value_copy(&(nv.value), iter); - if (0 == cmp(data, &nv)) { + if (0 == cmp(&nv, data)) { ret = darray_push(matched, iter); } } @@ -422,7 +422,7 @@ static value_t* object_array_find_prop(tk_object_t* obj, tk_compare_t cmp, const value_t* iter = &o->props[i]; tk_snprintf(name, TK_NAME_LEN, "%" PRIu32, i); value_copy(&(nv.value), iter); - if (0 == cmp(ctx, &nv)) { + if (0 == cmp(&nv, ctx)) { return iter; } } diff --git a/tests/object_array_test.cc b/tests/object_array_test.cc index 07fb20f5f..9b5f4787f 100644 --- a/tests/object_array_test.cc +++ b/tests/object_array_test.cc @@ -768,7 +768,7 @@ TEST(ObjectArray, push_and_remove) { TK_OBJECT_UNREF(obj); } -static int is_even(const void* ctx, const void* data) { +static int is_even(const void* data, const void* ctx) { const named_value_t* nv = (const named_value_t*)(data); uint32_t num = value_uint32(&nv->value); return (num % 2 == 0) ? 0 : -1;