1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Make struct action const

With GCC 4.3.1 on i686, this changes the sizes of sections as follows:

section            before       after   change
.text              682428      682492      +64
.rodata            212668      216352    +3684
.data               58092       54444    -3648
.debug_info       1482388     1482472      +84
.debug_abbrev      153714      153723       +9
.debug_line        272299      272319      +20
.debug_loc         540394      540372      -22
.debug_ranges      113784      113792       +8
Total             3917695     3917894     +199

The surprising .text change comes from src/config/dialogs.o.
Some of that is in get_keybinding_text(), where GCC changes the
order of basic blocks and apparently misses some optimizations.
This commit is contained in:
Kalle Olavi Niemitalo 2009-07-19 20:16:42 +03:00 committed by Kalle Olavi Niemitalo
parent 89c7e57890
commit 23fd2d58f4
4 changed files with 36 additions and 33 deletions

View File

@ -549,10 +549,11 @@ get_keybinding_action_box_item(enum keymap_id keymap_id, action_id_T action_id)
struct listbox_item *keymap_box_item[KEYMAP_MAX]; struct listbox_item *keymap_box_item[KEYMAP_MAX];
void void
init_keybinding_listboxes(struct keymap keymap_table[KEYMAP_MAX], struct action_list actions[]) init_keybinding_listboxes(struct keymap keymap_table[KEYMAP_MAX],
const struct action_list actions[])
{ {
struct listbox_item *root = &keybinding_browser.root; struct listbox_item *root = &keybinding_browser.root;
struct action *act; const struct action *act;
enum keymap_id keymap_id; enum keymap_id keymap_id;
/* Do it backwards because add_listbox_item() add to front /* Do it backwards because add_listbox_item() add to front
@ -577,7 +578,8 @@ init_keybinding_listboxes(struct keymap keymap_table[KEYMAP_MAX], struct action_
assert(act->desc); assert(act->desc);
#endif #endif
item = add_listbox_item(NULL, keymap_box, BI_FOLDER, act, -1); item = add_listbox_item(NULL, keymap_box, BI_FOLDER,
(void *) act, -1);
if (!item) continue; if (!item) continue;
item->expanded = 1; item->expanded = 1;
@ -644,7 +646,7 @@ get_keybinding_text(struct listbox_item *item, struct terminal *term)
return stracpy(keybinding_text_toggle ? keymap->str return stracpy(keybinding_text_toggle ? keymap->str
: _(keymap->desc, term)); : _(keymap->desc, term));
} else if (item->depth < 2) { } else if (item->depth < 2) {
struct action *action = item->udata; const struct action *action = item->udata;
return stracpy(keybinding_text_toggle ? action->str return stracpy(keybinding_text_toggle ? action->str
: _(action->desc, term)); : _(action->desc, term));
@ -686,7 +688,7 @@ get_keybinding_root(struct listbox_item *item)
if (item->depth == 0) return NULL; if (item->depth == 0) return NULL;
if (item->depth == 1) { if (item->depth == 1) {
struct action *action = item->udata; const struct action *action = item->udata;
return keymap_box_item[action->keymap_id]; return keymap_box_item[action->keymap_id];
} else { } else {
@ -700,7 +702,7 @@ static enum listbox_match
match_keybinding(struct listbox_item *item, struct terminal *term, match_keybinding(struct listbox_item *item, struct terminal *term,
unsigned char *text) unsigned char *text)
{ {
struct action *action = item->udata; const struct action *action = item->udata;
unsigned char *desc; unsigned char *desc;
if (item->depth != 1) if (item->depth != 1)
@ -872,7 +874,7 @@ push_kbdbind_add_button(struct dialog_data *dlg_data,
hop->action_id = keybinding->action_id; hop->action_id = keybinding->action_id;
hop->keymap_id = keybinding->keymap_id; hop->keymap_id = keybinding->keymap_id;
} else { } else {
struct action *action = item->udata; const struct action *action = item->udata;
hop->action_id = action->num; hop->action_id = action->num;
hop->keymap_id = action->keymap_id; hop->keymap_id = action->keymap_id;

View File

@ -16,7 +16,8 @@ void options_manager(struct session *);
void keybinding_manager(struct session *); void keybinding_manager(struct session *);
struct listbox_item *get_keybinding_action_box_item(enum keymap_id keymap_id, action_id_T action_id); struct listbox_item *get_keybinding_action_box_item(enum keymap_id keymap_id, action_id_T action_id);
void init_keybinding_listboxes(struct keymap keymap_table[], struct action_list actions[]); void init_keybinding_listboxes(struct keymap keymap_table[],
const struct action_list actions[]);
void done_keybinding_listboxes(void); void done_keybinding_listboxes(void);
#endif #endif

View File

@ -26,7 +26,7 @@
/* Fix namespace clash on MacOS. */ /* Fix namespace clash on MacOS. */
#define table table_elinks #define table table_elinks
static struct action_list action_table[KEYMAP_MAX]; static const struct action_list action_table[KEYMAP_MAX];
static struct keymap keymap_table[KEYMAP_MAX]; static struct keymap keymap_table[KEYMAP_MAX];
static LIST_OF(struct keybinding) keymaps[KEYMAP_MAX]; static LIST_OF(struct keybinding) keymaps[KEYMAP_MAX];
@ -229,7 +229,7 @@ static struct keymap keymap_table[] = {
* Config file helpers. * Config file helpers.
*/ */
static struct action * static const struct action *
get_action_from_keystroke(enum keymap_id keymap_id, get_action_from_keystroke(enum keymap_id keymap_id,
const unsigned char *keystroke_str) const unsigned char *keystroke_str)
{ {
@ -243,8 +243,8 @@ unsigned char *
get_action_name_from_keystroke(enum keymap_id keymap_id, get_action_name_from_keystroke(enum keymap_id keymap_id,
const unsigned char *keystroke_str) const unsigned char *keystroke_str)
{ {
struct action *action = get_action_from_keystroke(keymap_id, const struct action *action = get_action_from_keystroke(keymap_id,
keystroke_str); keystroke_str);
return action ? action->str : NULL; return action ? action->str : NULL;
} }
@ -252,7 +252,7 @@ get_action_name_from_keystroke(enum keymap_id keymap_id,
action_id_T action_id_T
get_action_from_string(enum keymap_id keymap_id, unsigned char *str) get_action_from_string(enum keymap_id keymap_id, unsigned char *str)
{ {
struct action *action; const struct action *action;
assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX); assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX);
@ -263,7 +263,7 @@ get_action_from_string(enum keymap_id keymap_id, unsigned char *str)
return -1; return -1;
} }
struct action * const struct action *
get_action(enum keymap_id keymap_id, action_id_T action_id) get_action(enum keymap_id keymap_id, action_id_T action_id)
{ {
assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX); assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX);
@ -277,7 +277,7 @@ get_action(enum keymap_id keymap_id, action_id_T action_id)
unsigned char * unsigned char *
get_action_name(enum keymap_id keymap_id, action_id_T action_id) get_action_name(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action ? action->str : NULL; return action ? action->str : NULL;
} }
@ -285,7 +285,7 @@ get_action_name(enum keymap_id keymap_id, action_id_T action_id)
static unsigned char * static unsigned char *
get_action_desc(enum keymap_id keymap_id, action_id_T action_id) get_action_desc(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action ? (action->desc ? action->desc : action->str) return action ? (action->desc ? action->desc : action->str)
: NULL; : NULL;
@ -523,23 +523,23 @@ add_actions_to_string(struct string *string, action_id_T action_ids[],
#undef KEYMAP_ID #undef KEYMAP_ID
#define KEYMAP_ID KEYMAP_MAIN #define KEYMAP_ID KEYMAP_MAIN
static struct action main_action_table[MAIN_ACTIONS + 1] = { static const struct action main_action_table[MAIN_ACTIONS + 1] = {
#include "config/actions-main.inc" #include "config/actions-main.inc"
}; };
#undef KEYMAP_ID #undef KEYMAP_ID
#define KEYMAP_ID KEYMAP_EDIT #define KEYMAP_ID KEYMAP_EDIT
static struct action edit_action_table[EDIT_ACTIONS + 1] = { static const struct action edit_action_table[EDIT_ACTIONS + 1] = {
#include "config/actions-edit.inc" #include "config/actions-edit.inc"
}; };
#undef KEYMAP_ID #undef KEYMAP_ID
#define KEYMAP_ID KEYMAP_MENU #define KEYMAP_ID KEYMAP_MENU
static struct action menu_action_table[MENU_ACTIONS + 1] = { static const struct action menu_action_table[MENU_ACTIONS + 1] = {
#include "config/actions-menu.inc" #include "config/actions-menu.inc"
}; };
static struct action_list action_table[KEYMAP_MAX] = { static const struct action_list action_table[KEYMAP_MAX] = {
{ main_action_table, sizeof_array(main_action_table) }, { main_action_table, sizeof_array(main_action_table) },
{ edit_action_table, sizeof_array(edit_action_table) }, { edit_action_table, sizeof_array(edit_action_table) },
{ menu_action_table, sizeof_array(menu_action_table) }, { menu_action_table, sizeof_array(menu_action_table) },
@ -844,11 +844,11 @@ add_default_keybindings(void)
*/ */
struct action_alias { struct action_alias {
unsigned char *str; const unsigned char *str;
action_id_T action_id; action_id_T action_id;
}; };
static struct action_alias main_action_aliases[] = { static const struct action_alias main_action_aliases[] = {
{ "back", ACT_MAIN_HISTORY_MOVE_BACK }, { "back", ACT_MAIN_HISTORY_MOVE_BACK },
{ "down", ACT_MAIN_MOVE_LINK_NEXT }, { "down", ACT_MAIN_MOVE_LINK_NEXT },
{ "download", ACT_MAIN_LINK_DOWNLOAD }, { "download", ACT_MAIN_LINK_DOWNLOAD },
@ -869,13 +869,13 @@ static struct action_alias main_action_aliases[] = {
{ NULL, 0 } { NULL, 0 }
}; };
static struct action_alias edit_action_aliases[] = { static const struct action_alias edit_action_aliases[] = {
{ "edit", ACT_EDIT_OPEN_EXTERNAL }, { "edit", ACT_EDIT_OPEN_EXTERNAL },
{ NULL, 0 } { NULL, 0 }
}; };
static struct action_alias *action_aliases[KEYMAP_MAX] = { static const struct action_alias *action_aliases[KEYMAP_MAX] = {
main_action_aliases, main_action_aliases,
edit_action_aliases, edit_action_aliases,
NULL, NULL,
@ -887,7 +887,7 @@ get_aliased_action(enum keymap_id keymap_id, unsigned char *action_str)
assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX); assert(keymap_id >= 0 && keymap_id < KEYMAP_MAX);
if (action_aliases[keymap_id]) { if (action_aliases[keymap_id]) {
struct action_alias *alias; const struct action_alias *alias;
for (alias = action_aliases[keymap_id]; alias->str; alias++) for (alias = action_aliases[keymap_id]; alias->str; alias++)
if (!strcmp(alias->str, action_str)) if (!strcmp(alias->str, action_str))

View File

@ -30,7 +30,7 @@ struct action {
}; };
struct action_list { struct action_list {
struct action *actions; const struct action *actions;
int num_actions; int num_actions;
}; };
struct keymap { struct keymap {
@ -104,7 +104,7 @@ struct keybinding *add_keybinding(enum keymap_id keymap_id, action_id_T action_i
int keybinding_exists(enum keymap_id keymap_id, struct term_event_keyboard *kbd, action_id_T *action_id); int keybinding_exists(enum keymap_id keymap_id, struct term_event_keyboard *kbd, action_id_T *action_id);
void free_keybinding(struct keybinding *); void free_keybinding(struct keybinding *);
struct action *get_action(enum keymap_id keymap_id, action_id_T action_id); const struct action *get_action(enum keymap_id keymap_id, action_id_T action_id);
unsigned char *get_action_name(enum keymap_id keymap_id, action_id_T action_id); unsigned char *get_action_name(enum keymap_id keymap_id, action_id_T action_id);
action_id_T get_action_from_string(enum keymap_id keymap_id, unsigned char *str); action_id_T get_action_from_string(enum keymap_id keymap_id, unsigned char *str);
unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id, unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id,
@ -113,7 +113,7 @@ unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id,
static inline unsigned int static inline unsigned int
action_is_anonymous_safe(enum keymap_id keymap_id, action_id_T action_id) action_is_anonymous_safe(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && !(action->flags & ACTION_RESTRICT_ANONYMOUS); return action && !(action->flags & ACTION_RESTRICT_ANONYMOUS);
} }
@ -121,7 +121,7 @@ action_is_anonymous_safe(enum keymap_id keymap_id, action_id_T action_id)
static inline unsigned int static inline unsigned int
action_requires_view_state(enum keymap_id keymap_id, action_id_T action_id) action_requires_view_state(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && (action->flags & ACTION_REQUIRE_VIEW_STATE); return action && (action->flags & ACTION_REQUIRE_VIEW_STATE);
} }
@ -129,7 +129,7 @@ action_requires_view_state(enum keymap_id keymap_id, action_id_T action_id)
static inline unsigned int static inline unsigned int
action_requires_location(enum keymap_id keymap_id, action_id_T action_id) action_requires_location(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && (action->flags & ACTION_REQUIRE_LOCATION); return action && (action->flags & ACTION_REQUIRE_LOCATION);
} }
@ -137,7 +137,7 @@ action_requires_location(enum keymap_id keymap_id, action_id_T action_id)
static inline unsigned int static inline unsigned int
action_prefix_is_link_number(enum keymap_id keymap_id, action_id_T action_id) action_prefix_is_link_number(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && (action->flags & ACTION_JUMP_TO_LINK); return action && (action->flags & ACTION_JUMP_TO_LINK);
} }
@ -145,7 +145,7 @@ action_prefix_is_link_number(enum keymap_id keymap_id, action_id_T action_id)
static inline unsigned int static inline unsigned int
action_requires_link(enum keymap_id keymap_id, action_id_T action_id) action_requires_link(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && (action->flags & ACTION_REQUIRE_LINK); return action && (action->flags & ACTION_REQUIRE_LINK);
} }
@ -153,7 +153,7 @@ action_requires_link(enum keymap_id keymap_id, action_id_T action_id)
static inline unsigned int static inline unsigned int
action_requires_form(enum keymap_id keymap_id, action_id_T action_id) action_requires_form(enum keymap_id keymap_id, action_id_T action_id)
{ {
struct action *action = get_action(keymap_id, action_id); const struct action *action = get_action(keymap_id, action_id);
return action && (action->flags & ACTION_REQUIRE_FORM); return action && (action->flags & ACTION_REQUIRE_FORM);
} }