1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

chore: change API name for lv_rb and lv_lru_rb (#4939)

This commit is contained in:
Benign X 2023-12-06 16:04:58 +08:00 committed by GitHub
parent f6eefe8eeb
commit 385c98bda4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 37 deletions

View File

@ -80,13 +80,13 @@ static void lv_freetype_cache_node_drop(lv_freetype_font_dsc_t * dsc);
static lv_freetype_outline_node_t * lv_freetype_outline_lookup(lv_freetype_font_dsc_t * dsc, uint32_t unicode_letter);
/*glyph dsc cache lru callbacks*/
static bool freetype_glyph_outline_alloc_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc);
static bool freetype_glyph_outline_create_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc);
static void freetype_glyph_outline_free_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc);
static lv_lru_rb_compare_res_t freetype_glyph_outline_cmp_cb(const lv_freetype_outline_node_t * node_a,
const lv_freetype_outline_node_t * node_b);
/*glyph dsc cache lru callbacks*/
static bool freetype_glyph_dsc_alloc_cb(lv_freetype_glyph_dsc_node_t * glyph_dsc_node, lv_freetype_font_dsc_t * dsc);
static bool freetype_glyph_dsc_create_cb(lv_freetype_glyph_dsc_node_t * glyph_dsc_node, lv_freetype_font_dsc_t * dsc);
static void freetype_glyph_dsc_free_cb(lv_freetype_glyph_dsc_node_t * glyph_dsc_node, lv_freetype_font_dsc_t * dsc);
static lv_lru_rb_compare_res_t freetype_glyph_dsc_cmp_cb(const lv_freetype_glyph_dsc_node_t * node_a,
const lv_freetype_glyph_dsc_node_t * node_b);
@ -268,11 +268,11 @@ static lv_freetype_cache_node_t * lv_freetype_cache_node_lookup(lv_freetype_cont
cache->glyph_dsc_lru = lv_lru_rb_create(sizeof(lv_freetype_glyph_dsc_node_t), LV_FREETYPE_GLYPH_DSC_CACHE_SIZE,
(lv_lru_rb_compare_cb_t)freetype_glyph_dsc_cmp_cb,
(lv_lru_rb_alloc_cb_t)freetype_glyph_dsc_alloc_cb,
(lv_lru_rb_create_cb_t)freetype_glyph_dsc_create_cb,
(lv_lru_rb_free_cb_t)freetype_glyph_dsc_free_cb);
cache->glyph_outline_lru = lv_lru_rb_create(sizeof(lv_freetype_outline_node_t), LV_FREETYPE_CACHE_FT_OUTLINES,
(lv_lru_rb_compare_cb_t)freetype_glyph_outline_cmp_cb,
(lv_lru_rb_alloc_cb_t)freetype_glyph_outline_alloc_cb,
(lv_lru_rb_create_cb_t)freetype_glyph_outline_create_cb,
(lv_lru_rb_free_cb_t)freetype_glyph_outline_free_cb);
LV_LOG_INFO("outline cache(name: %s, style: 0x%x) create %p, ref_cnt = %d",
@ -312,7 +312,7 @@ static void lv_freetype_cache_node_drop(lv_freetype_font_dsc_t * dsc)
* GLYPH DSC CACHE
*------------------*/
static bool freetype_glyph_dsc_alloc_cb(lv_freetype_glyph_dsc_node_t * glyph_dsc_node, lv_freetype_font_dsc_t * dsc)
static bool freetype_glyph_dsc_create_cb(lv_freetype_glyph_dsc_node_t * glyph_dsc_node, lv_freetype_font_dsc_t * dsc)
{
lv_font_glyph_dsc_t * dsc_out = &glyph_dsc_node->glyph_dsc;
@ -394,7 +394,7 @@ static bool freetype_get_glyph_dsc_cb(const lv_font_t * font,
tmp_node.glyph_index = glyph_index;
tmp_node.size = dsc->size;
lv_freetype_glyph_dsc_node_t * new_node = lv_lru_rb_get(cache_node->glyph_dsc_lru, &tmp_node, dsc);
lv_freetype_glyph_dsc_node_t * new_node = lv_lru_rb_get_or_create(cache_node->glyph_dsc_lru, &tmp_node, dsc);
if(!new_node) {
return false;
}
@ -411,7 +411,7 @@ static bool freetype_get_glyph_dsc_cb(const lv_font_t * font,
* OUTLINE CACHE
*------------------*/
static bool freetype_glyph_outline_alloc_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc)
static bool freetype_glyph_outline_create_cb(lv_freetype_outline_node_t * node, lv_freetype_font_dsc_t * dsc)
{
lv_freetype_outline_t outline;
outline = outline_create(dsc->context,
@ -466,7 +466,7 @@ static lv_freetype_outline_node_t * lv_freetype_outline_lookup(lv_freetype_font_
lv_freetype_outline_node_t tmp_node;
tmp_node.glyph_index = glyph_index;
lv_freetype_outline_node_t * new_node = lv_lru_rb_get(cache_node->glyph_outline_lru, &tmp_node, dsc);
lv_freetype_outline_node_t * new_node = lv_lru_rb_get_or_create(cache_node->glyph_outline_lru, &tmp_node, dsc);
if(!new_node) {
LV_LOG_ERROR("glyph outline lookup failed for glyph_index = %u", glyph_index);
return NULL;

View File

@ -65,7 +65,7 @@ struct _lv_lru_rb_t {
size_t max_size;
size_t size;
lv_lru_rb_alloc_cb_t alloc_cb;
lv_lru_rb_create_cb_t create_cb;
lv_lru_rb_free_cb_t free_cb;
};
/**********************
@ -90,15 +90,15 @@ inline static void ** get_lru_node(lv_lru_rb_t * lru, lv_rb_node_t * node);
**********************/
lv_lru_rb_t * lv_lru_rb_create(size_t node_size, size_t max_size, lv_lru_rb_compare_cb_t compare_cb,
lv_lru_rb_alloc_cb_t alloc_cb, lv_lru_rb_free_cb_t free_cb)
lv_lru_rb_create_cb_t create_cb, lv_lru_rb_free_cb_t free_cb)
{
LV_ASSERT_NULL(compare_cb);
LV_ASSERT_NULL(alloc_cb);
LV_ASSERT_NULL(create_cb);
LV_ASSERT_NULL(free_cb);
LV_ASSERT(node_size > 0);
LV_ASSERT(max_size > 0);
if(node_size == 0 || max_size == 0 || compare_cb == NULL || alloc_cb == NULL || free_cb == NULL) {
if(node_size == 0 || max_size == 0 || compare_cb == NULL || create_cb == NULL || free_cb == NULL) {
return NULL;
}
@ -119,7 +119,7 @@ lv_lru_rb_t * lv_lru_rb_create(size_t node_size, size_t max_size, lv_lru_rb_comp
lv_lru_rb_set_max_size(lru, max_size, NULL);
lv_lru_rb_set_compare_cb(lru, compare_cb, NULL);
lv_lru_rb_set_alloc_cb(lru, alloc_cb, NULL);
lv_lru_rb_set_create_cb(lru, create_cb, NULL);
lv_lru_rb_set_free_cb(lru, free_cb, NULL);
return lru;
@ -133,12 +133,12 @@ void lv_lru_rb_destroy(lv_lru_rb_t * lru, void * user_data)
return;
}
lv_lru_rb_clear(lru, user_data);
lv_lru_rb_drop_all(lru, user_data);
lv_free(lru);
}
void * lv_lru_rb_get(lv_lru_rb_t * lru, const void * key, void * user_data)
void * lv_lru_rb_get_or_create(lv_lru_rb_t * lru, const void * key, void * user_data)
{
LV_ASSERT_NULL(lru);
LV_ASSERT_NULL(key);
@ -167,7 +167,7 @@ void * lv_lru_rb_get(lv_lru_rb_t * lru, const void * key, void * user_data)
while(lru->size >= lru->max_size) {
lv_rb_node_t * tail = *(lv_rb_node_t **)_lv_ll_get_tail(&lru->lru_ll);
lv_lru_rb_reset(lru, tail->data, user_data);
lv_lru_rb_drop(lru, tail->data, user_data);
}
/*cache miss*/
@ -180,7 +180,7 @@ void * lv_lru_rb_get(lv_lru_rb_t * lru, const void * key, void * user_data)
return new_node->data;
}
void lv_lru_rb_reset(lv_lru_rb_t * lru, const void * key, void * user_data)
void lv_lru_rb_drop(lv_lru_rb_t * lru, const void * key, void * user_data)
{
LV_ASSERT_NULL(lru);
LV_ASSERT_NULL(key);
@ -197,7 +197,7 @@ void lv_lru_rb_reset(lv_lru_rb_t * lru, const void * key, void * user_data)
lru->free_cb(node->data, user_data);
void * lru_node = *get_lru_node(lru, node);
lv_rb_remove(&lru->rb, key);
lv_rb_drop(&lru->rb, key);
_lv_ll_remove(&lru->lru_ll, lru_node);
lv_free(lru_node);
@ -205,7 +205,7 @@ void lv_lru_rb_reset(lv_lru_rb_t * lru, const void * key, void * user_data)
lru->size--;
}
void lv_lru_rb_clear(lv_lru_rb_t * lru, void * user_data)
void lv_lru_rb_drop_all(lv_lru_rb_t * lru, void * user_data)
{
LV_ASSERT_NULL(lru);
@ -254,10 +254,10 @@ void lv_lru_rb_set_compare_cb(lv_lru_rb_t * lru, lv_lru_rb_compare_cb_t compare_
lru->rb.compare = (lv_rb_compare_t)compare_cb;
}
void lv_lru_rb_set_alloc_cb(lv_lru_rb_t * lru, lv_lru_rb_alloc_cb_t alloc_cb, void * user_data)
void lv_lru_rb_set_create_cb(lv_lru_rb_t * lru, lv_lru_rb_create_cb_t create_cb, void * user_data)
{
LV_UNUSED(user_data);
lru->alloc_cb = alloc_cb;
lru->create_cb = create_cb;
}
void lv_lru_rb_set_free_cb(lv_lru_rb_t * lru, lv_lru_rb_free_cb_t free_cb, void * user_data)
@ -284,7 +284,7 @@ static void * alloc_new_node(lv_lru_rb_t * lru, void * key, void * user_data)
lv_memcpy(node->data, key, lru->rb.size - sizeof(void *));
bool alloc_res = lru->alloc_cb(node->data, user_data);
bool alloc_res = lru->create_cb(node->data, user_data);
if(alloc_res == false)
goto FAILED_HANDLER2;
@ -300,7 +300,7 @@ FAILED_HANDLER1:
lru->free_cb(node->data, user_data);
FAILED_HANDLER2:
node = NULL;
lv_rb_remove(&lru->rb, key);
lv_rb_drop(&lru->rb, key);
FAILED_HANDLER3:
return node;
}

View File

@ -29,7 +29,7 @@ struct _lv_lru_rb_t;
typedef struct _lv_lru_rb_t lv_lru_rb_t;
typedef int8_t lv_lru_rb_compare_res_t;
typedef bool (*lv_lru_rb_alloc_cb_t)(void * node, void * user_data);
typedef bool (*lv_lru_rb_create_cb_t)(void * node, void * user_data);
typedef void (*lv_lru_rb_free_cb_t)(void * node, void * user_data);
typedef lv_lru_rb_compare_res_t (*lv_lru_rb_compare_cb_t)(const void * a, const void * b);
@ -37,17 +37,17 @@ typedef lv_lru_rb_compare_res_t (*lv_lru_rb_compare_cb_t)(const void * a, const
* GLOBAL PROTOTYPES
**********************/
lv_lru_rb_t * lv_lru_rb_create(size_t node_size, size_t max_size, lv_lru_rb_compare_cb_t compare_cb,
lv_lru_rb_alloc_cb_t alloc_cb, lv_lru_rb_free_cb_t free_cb);
lv_lru_rb_create_cb_t create_cb, lv_lru_rb_free_cb_t free_cb);
void lv_lru_rb_destroy(lv_lru_rb_t * lru, void * user_data);
void * lv_lru_rb_get(lv_lru_rb_t * lru, const void * key, void * user_data);
void lv_lru_rb_reset(lv_lru_rb_t * lru, const void * key, void * user_data);
void lv_lru_rb_clear(lv_lru_rb_t * lru, void * user_data);
void * lv_lru_rb_get_or_create(lv_lru_rb_t * lru, const void * key, void * user_data);
void lv_lru_rb_drop(lv_lru_rb_t * lru, const void * key, void * user_data);
void lv_lru_rb_drop_all(lv_lru_rb_t * lru, void * user_data);
void lv_lru_rb_set_max_size(lv_lru_rb_t * lru, size_t max_size, void * user_data);
size_t lv_lru_rb_get_max_size(lv_lru_rb_t * lru, void * user_data);
size_t lv_lru_rb_get_size(lv_lru_rb_t * lru, void * user_data);
size_t lv_lru_rb_get_free_size(lv_lru_rb_t * lru, void * user_data);
void lv_lru_rb_set_compare_cb(lv_lru_rb_t * lru, lv_lru_rb_compare_cb_t compare_cb, void * user_data);
void lv_lru_rb_set_alloc_cb(lv_lru_rb_t * lru, lv_lru_rb_alloc_cb_t alloc_cb, void * user_data);
void lv_lru_rb_set_create_cb(lv_lru_rb_t * lru, lv_lru_rb_create_cb_t create_cb, void * user_data);
void lv_lru_rb_set_free_cb(lv_lru_rb_t * lru, lv_lru_rb_free_cb_t free_cb, void * user_data);
/*************************
* GLOBAL VARIABLES

View File

@ -126,18 +126,18 @@ lv_rb_node_t * lv_rb_find(lv_rb_t * tree, const void * key)
return NULL;
}
bool lv_rb_remove(lv_rb_t * tree, const void * key)
void * lv_rb_remove(lv_rb_t * tree, const void * key)
{
LV_ASSERT_NULL(tree);
if(tree == NULL) {
return false;
return NULL;
}
lv_rb_node_t * node = lv_rb_find(tree, key);
LV_ASSERT_NULL(node);
if(node == NULL) {
LV_LOG_WARN("rb delete %d not found", (int)(uintptr_t)key);
return false;
return NULL;
}
lv_rb_node_t * child = NULL;
@ -185,9 +185,9 @@ bool lv_rb_remove(lv_rb_t * tree, const void * key)
rb_delete_color(tree, child, parent);
}
lv_free(node->data);
void * data = node->data;
lv_free(node);
return true;
return data;
}
child = node->right != NULL ? node->right : node->left;
@ -214,9 +214,24 @@ bool lv_rb_remove(lv_rb_t * tree, const void * key)
rb_delete_color(tree, child, parent);
}
lv_free(node->data);
void * data = node->data;
lv_free(node);
return true;
return data;
}
bool lv_rb_drop(lv_rb_t * tree, const void * key)
{
LV_ASSERT_NULL(tree);
if(tree == NULL) {
return NULL;
}
void * data = lv_rb_remove(tree, key);
if(data) {
lv_free(data);
return true;
}
return false;
}
void lv_rb_destroy(lv_rb_t * tree)

View File

@ -55,7 +55,8 @@ typedef struct {
bool lv_rb_init(lv_rb_t * tree, lv_rb_compare_t compare, size_t node_size);
lv_rb_node_t * lv_rb_insert(lv_rb_t * tree, void * key);
lv_rb_node_t * lv_rb_find(lv_rb_t * tree, const void * key);
bool lv_rb_remove(lv_rb_t * tree, const void * key);
void * lv_rb_remove(lv_rb_t * tree, const void * key);
bool lv_rb_drop(lv_rb_t * tree, const void * key);
lv_rb_node_t * lv_rb_minimum(lv_rb_t * node);
lv_rb_node_t * lv_rb_maximum(lv_rb_t * node);
lv_rb_node_t * lv_rb_minimum_from(lv_rb_node_t * node);