optimize const data

This commit is contained in:
lixianjing 2019-11-13 10:24:46 +08:00
parent f6b1867816
commit 2330ae048e
18 changed files with 105 additions and 103 deletions

View File

@ -42,13 +42,13 @@ static ret_t dialog_on_add_child(widget_t* widget, widget_t* child) {
return RET_CONTINUE;
}
static const char* s_dialog_properties[] = {WIDGET_PROP_ANIM_HINT,
WIDGET_PROP_OPEN_ANIM_HINT,
WIDGET_PROP_MOVE_FOCUS_PREV_KEY,
WIDGET_PROP_MOVE_FOCUS_NEXT_KEY,
WIDGET_PROP_CLOSE_ANIM_HINT,
WIDGET_PROP_THEME,
NULL};
static const char* const s_dialog_properties[] = {WIDGET_PROP_ANIM_HINT,
WIDGET_PROP_OPEN_ANIM_HINT,
WIDGET_PROP_MOVE_FOCUS_PREV_KEY,
WIDGET_PROP_MOVE_FOCUS_NEXT_KEY,
WIDGET_PROP_CLOSE_ANIM_HINT,
WIDGET_PROP_THEME,
NULL};
static ret_t dialog_set_prop(widget_t* widget, const char* name, const value_t* v) {
dialog_t* dialog = DIALOG(widget);

View File

@ -28,7 +28,7 @@ ret_t image_loader_load(image_loader_t* loader, const asset_info_t* asset, bitma
return loader->load(loader, asset, bitmap);
}
#define MAX_IMAGE_LOADERS 5
#define MAX_IMAGE_LOADERS 3
static image_loader_t* s_image_loaders[MAX_IMAGE_LOADERS];
ret_t image_loader_register(image_loader_t* loader) {

View File

@ -1,4 +1,4 @@
/**
/**
* File: widget.c
* Author: AWTK Develop Team
* Brief: basic class of all widget
@ -2680,28 +2680,28 @@ ret_t widget_prepare_text_style(widget_t* widget, canvas_t* c) {
return RET_OK;
}
static const char* s_widget_persistent_props[] = {WIDGET_PROP_NAME,
WIDGET_PROP_STYLE,
WIDGET_PROP_TR_TEXT,
WIDGET_PROP_TEXT,
WIDGET_PROP_ANIMATION,
WIDGET_PROP_ENABLE,
WIDGET_PROP_VISIBLE,
WIDGET_PROP_FLOATING,
WIDGET_PROP_CHILDREN_LAYOUT,
WIDGET_PROP_SELF_LAYOUT,
WIDGET_PROP_OPACITY,
WIDGET_PROP_FOCUSED,
WIDGET_PROP_FOCUSABLE,
WIDGET_PROP_WITH_FOCUS_STATE,
WIDGET_PROP_SENSITIVE,
NULL};
static const char* const s_widget_persistent_props[] = {WIDGET_PROP_NAME,
WIDGET_PROP_STYLE,
WIDGET_PROP_TR_TEXT,
WIDGET_PROP_TEXT,
WIDGET_PROP_ANIMATION,
WIDGET_PROP_ENABLE,
WIDGET_PROP_VISIBLE,
WIDGET_PROP_FLOATING,
WIDGET_PROP_CHILDREN_LAYOUT,
WIDGET_PROP_SELF_LAYOUT,
WIDGET_PROP_OPACITY,
WIDGET_PROP_FOCUSED,
WIDGET_PROP_FOCUSABLE,
WIDGET_PROP_WITH_FOCUS_STATE,
WIDGET_PROP_SENSITIVE,
NULL};
const char** widget_get_persistent_props(void) {
const char* const* widget_get_persistent_props(void) {
return s_widget_persistent_props;
}
static ret_t widget_copy_props(widget_t* clone, widget_t* widget, const char** properties) {
static ret_t widget_copy_props(widget_t* clone, widget_t* widget, const char* const* properties) {
if (properties != NULL) {
value_t v;
value_t defval;
@ -2771,7 +2771,7 @@ widget_t* widget_clone(widget_t* widget, widget_t* parent) {
#define PROP_EQ(prop) (widget->prop == other->prop)
bool_t widget_equal(widget_t* widget, widget_t* other) {
bool_t ret = FALSE;
const char** properties = NULL;
const char* const* properties = NULL;
return_value_if_fail(widget != NULL && other != NULL, FALSE);
ret = PROP_EQ(opacity) && PROP_EQ(enable) && PROP_EQ(visible) && PROP_EQ(vt) && PROP_EQ(x) &&

View File

@ -87,9 +87,9 @@ struct _widget_vtable_t {
uint32_t size;
const char* type;
/*克隆widget时需要复制的属性*/
const char** clone_properties;
const char* const* clone_properties;
/*持久化widget时需要保存的属性*/
const char** persistent_properties;
const char* const* persistent_properties;
/**
*
*/
@ -2052,7 +2052,7 @@ ret_t widget_on_paint_end(widget_t* widget, canvas_t* c);
#define WIDGET(w) ((widget_t*)(w))
const char** widget_get_persistent_props(void);
const char* const* widget_get_persistent_props(void);
bool_t widget_is_instance_of(widget_t* widget, const widget_vtable_t* vt);
#define WIDGET_IS_INSTANCE_OF(widget, name) widget_is_instance_of(widget, TK_REF_VTABLE(name))

View File

@ -22,10 +22,17 @@
#include "rtos.h"
static volatile uint64_t g_sys_tick;
static bool_t s_sys_tick_enable = FALSE;
void sys_tick_enable(bool_t enable) {
s_sys_tick_enable = enable;
}
void SysTick_Handler(void) {
g_sys_tick++;
rtos_tick();
if (s_sys_tick_enable) {
g_sys_tick++;
rtos_tick();
}
}
uint64_t get_time_ms64() {
@ -35,11 +42,3 @@ uint64_t get_time_ms64() {
void sleep_ms(uint32_t ms) {
rtos_delay(ms);
}
void delay_ms(uint32_t ms) {
sleep_ms(ms);
}
void delay_us(uint32_t us) {
sleep_ms(1);
}

View File

@ -39,5 +39,3 @@ void sleep_ms(uint32_t ms) {
count++;
}
}

View File

@ -1,4 +1,4 @@
/**
/**
* File: mem.c
* Author: AWTK Develop Team
* Brief: simple memory manager
@ -246,6 +246,10 @@ static void* tk_realloc_impl(void* ptr, uint32_t size) {
ret_t tk_mem_init(void* buffer, uint32_t size) {
return_value_if_fail(buffer != NULL && size > MIN_SIZE, RET_BAD_PARAMS);
if (s_mem_info.buffer != NULL) {
return RET_FAIL;
}
memset(buffer, 0x00, size);
s_mem_info.buffer = (char*)buffer;
s_mem_info.size = size;

View File

@ -53,7 +53,7 @@ ret_t ui_widget_serialize_prop(ui_builder_t* writer, const char* name, value_t*
}
static ret_t ui_widget_serialize_props(ui_builder_t* writer, widget_t* widget,
const char** properties) {
const char* const* properties) {
value_t v;
value_t defv;
uint32_t i = 0;
@ -101,7 +101,7 @@ ret_t ui_widget_serialize(ui_builder_t* writer, widget_t* widget) {
ui_widget_serialize_props(writer, widget, widget_get_persistent_props());
if (widget->vt->clone_properties || widget->vt->persistent_properties) {
const char** properties = widget->vt->persistent_properties;
const char* const* properties = widget->vt->persistent_properties;
if (properties == NULL) {
properties = widget->vt->clone_properties;
}

View File

@ -199,7 +199,7 @@ static ret_t button_on_destroy(widget_t* widget) {
return button_remove_timer(widget);
}
static const char* s_button_properties[] = {WIDGET_PROP_REPEAT, NULL};
static const char* const s_button_properties[] = {WIDGET_PROP_REPEAT, NULL};
TK_DECL_VTABLE(button) = {.size = sizeof(button_t),
.type = WIDGET_TYPE_BUTTON,

View File

@ -71,8 +71,8 @@ static ret_t color_tile_set_prop(widget_t* widget, const char* name, const value
return RET_NOT_FOUND;
}
static const char* s_color_tile_properties[] = {WIDGET_PROP_BG_COLOR, WIDGET_PROP_BORDER_COLOR,
NULL};
static const char* const s_color_tile_properties[] = {WIDGET_PROP_BG_COLOR,
WIDGET_PROP_BORDER_COLOR, NULL};
TK_DECL_VTABLE(color_tile) = {.size = sizeof(color_tile_t),
.type = WIDGET_TYPE_COLOR_TILE,
.parent = TK_PARENT_VTABLE(widget),

View File

@ -31,24 +31,24 @@
static ret_t combo_box_on_button_click(void* ctx, event_t* e);
const char* s_combo_box_properties[] = {WIDGET_PROP_MIN,
WIDGET_PROP_MAX,
WIDGET_PROP_STEP,
WIDGET_PROP_INPUT_TYPE,
WIDGET_PROP_READONLY,
WIDGET_PROP_AUTO_FIX,
WIDGET_PROP_MARGIN,
WIDGET_PROP_LEFT_MARGIN,
WIDGET_PROP_RIGHT_MARGIN,
WIDGET_PROP_TOP_MARGIN,
WIDGET_PROP_BOTTOM_MARGIN,
WIDGET_PROP_TIPS,
WIDGET_PROP_OPTIONS,
WIDGET_PROP_ITEM_HEIGHT,
WIDGET_PROP_OPEN_WINDOW,
WIDGET_PROP_SELECTED_INDEX,
WIDGET_PROP_LOCALIZE_OPTIONS,
NULL};
const char* const s_combo_box_properties[] = {WIDGET_PROP_MIN,
WIDGET_PROP_MAX,
WIDGET_PROP_STEP,
WIDGET_PROP_INPUT_TYPE,
WIDGET_PROP_READONLY,
WIDGET_PROP_AUTO_FIX,
WIDGET_PROP_MARGIN,
WIDGET_PROP_LEFT_MARGIN,
WIDGET_PROP_RIGHT_MARGIN,
WIDGET_PROP_TOP_MARGIN,
WIDGET_PROP_BOTTOM_MARGIN,
WIDGET_PROP_TIPS,
WIDGET_PROP_OPTIONS,
WIDGET_PROP_ITEM_HEIGHT,
WIDGET_PROP_OPEN_WINDOW,
WIDGET_PROP_SELECTED_INDEX,
WIDGET_PROP_LOCALIZE_OPTIONS,
NULL};
static ret_t combo_box_active(widget_t* widget);
static ret_t combo_box_add_selected_index(widget_t* widget, int32_t delta);

View File

@ -41,7 +41,7 @@ static uint32_t count_char(const char* p, char c) {
static wchar_t* digit_clock_translate_wday(wchar_t* str, uint32_t size, uint32_t wday) {
return_value_if_fail(wday < 7, NULL);
static const char* wdays[] = {
static const char* const wdays[] = {
"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat",
};
@ -52,8 +52,8 @@ static wchar_t* digit_clock_translate_wday(wchar_t* str, uint32_t size, uint32_t
static wchar_t* digit_clock_translate_month(wchar_t* str, uint32_t size, uint32_t month) {
return_value_if_fail(month < 13, NULL);
static const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
static const char* const months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
const char* utf8 = locale_info_tr(locale_info(), months[month - 1]);
return utf8_to_utf16(utf8, str, size);
@ -219,7 +219,7 @@ static ret_t digit_clock_on_destroy(widget_t* widget) {
return RET_OK;
}
static const char* s_digit_clock_properties[] = {WIDGET_PROP_FORMAT, NULL};
static const char* const s_digit_clock_properties[] = {WIDGET_PROP_FORMAT, NULL};
TK_DECL_VTABLE(digit_clock) = {.size = sizeof(digit_clock_t),
.type = WIDGET_TYPE_DIGIT_CLOCK,

View File

@ -165,8 +165,8 @@ static ret_t dragger_set_prop(widget_t* widget, const char* name, const value_t*
return RET_NOT_FOUND;
}
static const char* s_dragger_clone_properties[] = {WIDGET_PROP_X_MIN, WIDGET_PROP_X_MAX,
WIDGET_PROP_Y_MIN, WIDGET_PROP_Y_MAX, NULL};
static const char* const s_dragger_clone_properties[] = {
WIDGET_PROP_X_MIN, WIDGET_PROP_X_MAX, WIDGET_PROP_Y_MIN, WIDGET_PROP_Y_MAX, NULL};
TK_DECL_VTABLE(dragger) = {.size = sizeof(dragger_t),
.type = WIDGET_TYPE_DRAGGER,
.clone_properties = s_dragger_clone_properties,

View File

@ -1133,20 +1133,20 @@ static ret_t edit_hook_children_button(const idle_info_t* info) {
return RET_REMOVE;
}
const char* s_edit_properties[] = {WIDGET_PROP_MIN,
WIDGET_PROP_MAX,
WIDGET_PROP_STEP,
WIDGET_PROP_INPUT_TYPE,
WIDGET_PROP_READONLY,
WIDGET_PROP_AUTO_FIX,
WIDGET_PROP_MARGIN,
WIDGET_PROP_LEFT_MARGIN,
WIDGET_PROP_RIGHT_MARGIN,
WIDGET_PROP_TOP_MARGIN,
WIDGET_PROP_BOTTOM_MARGIN,
WIDGET_PROP_TIPS,
WIDGET_PROP_PASSWORD_VISIBLE,
NULL};
const char* const s_edit_properties[] = {WIDGET_PROP_MIN,
WIDGET_PROP_MAX,
WIDGET_PROP_STEP,
WIDGET_PROP_INPUT_TYPE,
WIDGET_PROP_READONLY,
WIDGET_PROP_AUTO_FIX,
WIDGET_PROP_MARGIN,
WIDGET_PROP_LEFT_MARGIN,
WIDGET_PROP_RIGHT_MARGIN,
WIDGET_PROP_TOP_MARGIN,
WIDGET_PROP_BOTTOM_MARGIN,
WIDGET_PROP_TIPS,
WIDGET_PROP_PASSWORD_VISIBLE,
NULL};
TK_DECL_VTABLE(edit) = {.size = sizeof(edit_t),
.type = WIDGET_TYPE_EDIT,
.focusable = TRUE,

View File

@ -94,11 +94,12 @@ static ret_t image_set_prop(widget_t* widget, const char* name, const value_t* v
}
}
static const char* s_image_clone_properties[] = {WIDGET_PROP_IMAGE, WIDGET_PROP_DRAW_TYPE,
WIDGET_PROP_SCALE_X, WIDGET_PROP_SCALE_Y,
WIDGET_PROP_ANCHOR_X, WIDGET_PROP_ANCHOR_Y,
WIDGET_PROP_ROTATION, WIDGET_PROP_CLICKABLE,
WIDGET_PROP_SELECTABLE, NULL};
static const char* const s_image_clone_properties[] = {
WIDGET_PROP_IMAGE, WIDGET_PROP_DRAW_TYPE,
WIDGET_PROP_SCALE_X, WIDGET_PROP_SCALE_Y,
WIDGET_PROP_ANCHOR_X, WIDGET_PROP_ANCHOR_Y,
WIDGET_PROP_ROTATION, WIDGET_PROP_CLICKABLE,
WIDGET_PROP_SELECTABLE, NULL};
TK_DECL_VTABLE(image) = {.size = sizeof(image_t),
.type = WIDGET_TYPE_IMAGE,

View File

@ -24,7 +24,7 @@
#include "base/enums.h"
#include "widgets/overlay.h"
static const char* s_overlay_properties[] = {
static const char* const s_overlay_properties[] = {
WIDGET_PROP_MOVE_FOCUS_PREV_KEY, WIDGET_PROP_MOVE_FOCUS_NEXT_KEY, WIDGET_PROP_THEME, NULL};
TK_DECL_VTABLE(overlay) = {.type = WIDGET_TYPE_OVERLAY,

View File

@ -109,7 +109,7 @@ static ret_t pages_set_prop(widget_t* widget, const char* name, const value_t* v
return RET_NOT_FOUND;
}
static const char* s_pages_clone_properties[] = {WIDGET_PROP_VALUE, NULL};
static const char* const s_pages_clone_properties[] = {WIDGET_PROP_VALUE, NULL};
TK_DECL_VTABLE(pages) = {.size = sizeof(pages_t),
.inputable = TRUE,

View File

@ -106,15 +106,15 @@ static ret_t popup_on_event(widget_t* widget, event_t* e) {
return window_base_on_event(widget, e);
}
static const char* s_popup_properties[] = {WIDGET_PROP_ANIM_HINT,
WIDGET_PROP_OPEN_ANIM_HINT,
WIDGET_PROP_CLOSE_ANIM_HINT,
WIDGET_PROP_THEME,
WIDGET_PROP_CLOSE_WHEN_CLICK,
WIDGET_PROP_CLOSE_WHEN_CLICK_OUTSIDE,
WIDGET_PROP_MOVE_FOCUS_PREV_KEY,
WIDGET_PROP_MOVE_FOCUS_NEXT_KEY,
NULL};
static const char* const s_popup_properties[] = {WIDGET_PROP_ANIM_HINT,
WIDGET_PROP_OPEN_ANIM_HINT,
WIDGET_PROP_CLOSE_ANIM_HINT,
WIDGET_PROP_THEME,
WIDGET_PROP_CLOSE_WHEN_CLICK,
WIDGET_PROP_CLOSE_WHEN_CLICK_OUTSIDE,
WIDGET_PROP_MOVE_FOCUS_PREV_KEY,
WIDGET_PROP_MOVE_FOCUS_NEXT_KEY,
NULL};
TK_DECL_VTABLE(popup) = {.size = sizeof(popup_t),
.type = WIDGET_TYPE_POPUP,