summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b126dbb)
raw | patch | inline | side by side (parent: b126dbb)
author | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:05:02 +0000 (12:05 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:05:02 +0000 (12:05 +0200) |
Compile time initialization saves resources, compared to run-time
initialization. Declare all screen_function structs as global
variables, and remove all get functions.
initialization. Declare all screen_function structs as global
variables, and remove all get functions.
diff --git a/src/screen.c b/src/screen.c
index 0b335efa903f27bab16bdb1531ead40bddef391d..ea21a1af8fae1a5679b9815126df2b60cad72e1c 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
/* screens */
-extern struct screen_functions *get_screen_playlist(void);
-extern struct screen_functions *get_screen_browse(void);
-extern struct screen_functions *get_screen_help(void);
-extern struct screen_functions *get_screen_search(void);
-extern struct screen_functions *get_screen_artist(void);
-extern struct screen_functions *get_screen_keydef(void);
-extern struct screen_functions *get_screen_clock(void);
-extern struct screen_functions *get_screen_lyrics(void);
+extern const struct screen_functions screen_playlist;
+extern const struct screen_functions screen_browse;
+#ifdef ENABLE_ARTIST_SCREEN
+extern const struct screen_functions screen_artist;
+#endif
+extern const struct screen_functions screen_help;
+#ifdef ENABLE_SEARCH_SCREEN
+extern const struct screen_functions screen_search;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
+extern const struct screen_functions screen_keydef;
+#endif
+#ifdef ENABLE_CLOCK_SCREEN
+extern const struct screen_functions screen_clock;
+#endif
+extern const struct screen_functions screen_lyrics;
typedef struct screen_functions * (*screen_get_mode_functions_fn_t) (void);
{
gint id;
const gchar *name;
- screen_get_mode_functions_fn_t get_mode_functions;
+ const struct screen_functions *functions;
} screens[] = {
- { SCREEN_PLAYLIST_ID, "playlist", get_screen_playlist },
- { SCREEN_BROWSE_ID, "browse", get_screen_browse },
+ { SCREEN_PLAYLIST_ID, "playlist", &screen_playlist },
+ { SCREEN_BROWSE_ID, "browse", &screen_browse },
#ifdef ENABLE_ARTIST_SCREEN
- { SCREEN_ARTIST_ID, "artist", get_screen_artist },
+ { SCREEN_ARTIST_ID, "artist", &screen_artist },
#endif
- { SCREEN_HELP_ID, "help", get_screen_help },
+ { SCREEN_HELP_ID, "help", &screen_help },
#ifdef ENABLE_SEARCH_SCREEN
- { SCREEN_SEARCH_ID, "search", get_screen_search },
+ { SCREEN_SEARCH_ID, "search", &screen_search },
#endif
#ifdef ENABLE_KEYDEF_SCREEN
- { SCREEN_KEYDEF_ID, "keydef", get_screen_keydef },
+ { SCREEN_KEYDEF_ID, "keydef", &screen_keydef },
#endif
#ifdef ENABLE_CLOCK_SCREEN
- { SCREEN_CLOCK_ID, "clock", get_screen_clock },
+ { SCREEN_CLOCK_ID, "clock", &screen_clock },
#endif
#ifdef ENABLE_LYRICS_SCREEN
- { SCREEN_LYRICS_ID, "lyrics", get_screen_lyrics },
+ { SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
#endif
- { G_MAXINT, NULL, NULL }
+ { G_MAXINT, NULL, NULL }
};
static gboolean welcome = TRUE;
static screen_t *screen = NULL;
-static struct screen_functions *mode_fn = NULL;
+static const struct screen_functions *mode_fn = NULL;
static int seek_id = -1;
static int seek_target_time = 0;
/* get functions for the new mode */
new_mode = lookup_mode(id);
- if (new_mode>=0 && screens[new_mode].get_mode_functions) {
+ if (new_mode >= 0 && screens[new_mode].functions) {
D("switch_screen(%s)\n", screens[new_mode].name );
- mode_fn = screens[new_mode].get_mode_functions();
+ mode_fn = screens[new_mode].functions;
screen->mode = new_mode;
}
/* close and exit all screens (playlist,browse,help...) */
i=0;
- while (screens[i].get_mode_functions) {
- struct screen_functions *sf = screens[i].get_mode_functions();
+ while (screens[i].functions) {
+ const struct screen_functions *sf = screens[i].functions;
- if (sf && sf->close)
+ if (sf->close)
sf->close();
- if (sf && sf->exit)
+ if (sf->exit)
sf->exit();
i++;
/* close and exit all screens (playlist,browse,help...) */
i=0;
- while (screens[i].get_mode_functions) {
- struct screen_functions *sf = screens[i].get_mode_functions();
+ while (screens[i].functions) {
+ const struct screen_functions *sf = screens[i].functions;
- if (sf && sf->resize)
+ if (sf->resize)
sf->resize(screen->main_window.cols, screen->main_window.rows);
i++;
/* initialize screens */
i=0;
- while (screens[i].get_mode_functions) {
- struct screen_functions *fn = screens[i].get_mode_functions();
+ while (screens[i].functions) {
+ const struct screen_functions *fn = screens[i].functions;
- if (fn && fn->init)
+ if (fn->init)
fn->init(screen->main_window.w,
screen->main_window.cols,
screen->main_window.rows);
mode_fn = NULL;
switch_screen_mode(screen_get_id(options.screen_list[0]), c);
#else
- mode_fn = get_screen_playlist();
+ mode_fn = &screen_playlist;
#endif
if( mode_fn && mode_fn->open )
diff --git a/src/screen.h b/src/screen.h
index 06ce71da36b0297ee4e6dfcdd76265a0d28fcb34..7aa72d7d296188e39f73a15f0b26460c1cc6ce34 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
struct list_window *lw, int lw_length,
unsigned long *bstate, int *row);
-struct screen_functions *
-get_screen_search(void);
-
-struct screen_functions *
-get_screen_browse(void);
-
-struct screen_functions *
-get_screen_playlist(void);
-
-struct screen_functions *
-get_screen_help(void);
-
-struct screen_functions *
-get_screen_lyrics(void);
-
-struct screen_functions *
-get_screen_keydef(void);
-
-struct screen_functions *
-get_screen_clock(void);
-
#endif
diff --git a/src/screen_artist.c b/src/screen_artist.c
index fa42f1f7794aa34f22fddae02e0ecfb28ed34f28..f010a089dcaeea11ef1582c5dcadf01ad40c249a 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
return 0;
}
-screen_functions_t *
-get_screen_artist(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = init;
- functions.exit = quit;
- functions.open = open;
- functions.close = close;
- functions.resize = resize;
- functions.paint = paint;
- functions.update = update;
- functions.cmd = artist_cmd;
- functions.get_lw = get_filelist_window;
- functions.get_title = get_title;
-
- return &functions;
-}
-
+const struct screen_functions screen_artist = {
+ .init = init,
+ .exit = quit,
+ .open = open,
+ .close = close,
+ .resize = resize,
+ .paint = paint,
+ .update = update,
+ .cmd = artist_cmd,
+ .get_lw = get_filelist_window,
+ .get_title = get_title,
+};
#endif /* ENABLE_ARTIST_SCREEN */
diff --git a/src/screen_clock.c b/src/screen_clock.c
index 493150bb056fffd185049476ae4e5b516a8b3ecd..11d2da1b2dbd15f168ea2a936a3604c50c633105 100644 (file)
--- a/src/screen_clock.c
+++ b/src/screen_clock.c
return 0;
}
-screen_functions_t *
-get_screen_clock(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = clock_init;
- functions.exit = clock_exit;
- functions.open = clock_open;
- functions.close = clock_close;
- functions.resize = clock_resize;
- functions.paint = clock_paint;
- functions.update = clock_update;
- functions.cmd = clock_cmd;
- functions.get_lw = NULL;
- functions.get_title = clock_title;
-
- return &functions;
-}
+const struct screen_functions screen_clock = {
+ .init = clock_init,
+ .exit = clock_exit,
+ .open = clock_open,
+ .close = clock_close,
+ .resize = clock_resize,
+ .paint = clock_paint,
+ .update = clock_update,
+ .cmd = clock_cmd,
+ .get_title = clock_title,
+};
#endif
diff --git a/src/screen_file.c b/src/screen_file.c
index c480961c4b9ebab4cde59bce4b315d9302a98687..e996aba0903d3ebbc211348cd3afc6881ddde93b 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
return lw;
}
-screen_functions_t *
-get_screen_browse(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = browse_init;
- functions.exit = browse_exit;
- functions.open = browse_open;
- functions.close = browse_close;
- functions.resize = browse_resize;
- functions.paint = browse_paint;
- functions.update = browse_update;
- functions.cmd = browse_cmd;
- functions.get_lw = get_filelist_window;
- functions.get_title = browse_title;
-
- return &functions;
-}
+const struct screen_functions screen_browse = {
+ .init = browse_init,
+ .exit = browse_exit,
+ .open = browse_open,
+ .close = browse_close,
+ .resize = browse_resize,
+ .paint = browse_paint,
+ .update = browse_update,
+ .cmd = browse_cmd,
+ .get_lw = get_filelist_window,
+ .get_title = browse_title,
+};
diff --git a/src/screen_help.c b/src/screen_help.c
index d225b3d6d396b08b6afab88ea450191c127a7b22..bfefc1e7abb3040fb06c106519f87e59ea215203 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
return lw;
}
-screen_functions_t *
-get_screen_help(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = help_init;
- functions.exit = help_exit;
- functions.open = NULL;
- functions.close = NULL;
- functions.resize = help_resize;
- functions.paint = help_paint;
- functions.update = help_update;
- functions.cmd = help_cmd;
- functions.get_lw = help_lw;
- functions.get_title = help_title;
-
- return &functions;
-}
+const struct screen_functions screen_help = {
+ .init = help_init,
+ .exit = help_exit,
+ .resize = help_resize,
+ .paint = help_paint,
+ .update = help_update,
+ .cmd = help_cmd,
+ .get_lw = help_lw,
+ .get_title = help_title,
+};
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 44c84ca42f0f8747f66e889acc92868c68e1fe9c..1fde75d4540eba24d7b3071ca9507ee8e432e455 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
return lw;
}
-screen_functions_t *
-get_screen_keydef(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = keydef_init;
- functions.exit = keydef_exit;
- functions.open = keydef_open;
- functions.close = keydef_close;
- functions.resize = keydef_resize;
- functions.paint = keydef_paint;
- functions.update = keydef_update;
- functions.cmd = keydef_cmd;
- functions.get_lw = keydef_lw;
- functions.get_title = keydef_title;
-
- return &functions;
-}
-
+const struct screen_functions screen_keydef = {
+ .init = keydef_init,
+ .exit = keydef_exit,
+ .open = keydef_open,
+ .close = keydef_close,
+ .resize = keydef_resize,
+ .paint = keydef_paint,
+ .update = keydef_update,
+ .cmd = keydef_cmd,
+ .get_lw = keydef_lw,
+ .get_title = keydef_title,
+};
#endif
diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c
index 2f63fb0ae62be5d5cd72cbffa117c8b5d07b9ffd..885a35a766c843eac8aa3878e19f41b5b2288b49 100644 (file)
--- a/src/screen_lyrics.c
+++ b/src/screen_lyrics.c
return lw;
}
-screen_functions_t *
-get_screen_lyrics(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = lyrics_screen_init;
- functions.exit = lyrics_exit;
- functions.open = lyrics_open;
- functions.close = NULL;
- functions.resize = lyrics_resize;
- functions.paint = lyrics_paint;
- functions.update = lyrics_update;
- functions.cmd = lyrics_cmd;
- functions.get_lw = lyrics_lw;
- functions.get_title = lyrics_title;
-
- return &functions;
-}
+const struct screen_functions screen_lyrics = {
+ .init = lyrics_screen_init,
+ .exit = lyrics_exit,
+ .open = lyrics_open,
+ .close = NULL,
+ .resize = lyrics_resize,
+ .paint = lyrics_paint,
+ .update = lyrics_update,
+ .cmd = lyrics_cmd,
+ .get_lw = lyrics_lw,
+ .get_title = lyrics_title,
+};
+
#endif /* ENABLE_LYRICS_SCREEN */
diff --git a/src/screen_play.c b/src/screen_play.c
index 32c08ea73a21ede201215cf8fd2e8635bc7bdf68..22d7198aa7e685f9e7831f3f9fbd3a92f8a3d91e 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
return lw;
}
-screen_functions_t *
-get_screen_playlist(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = play_init;
- functions.exit = play_exit;
- functions.open = play_open;
- functions.close = NULL;
- functions.resize = play_resize;
- functions.paint = play_paint;
- functions.update = play_update;
- functions.cmd = play_cmd;
- functions.get_lw = play_lw;
- functions.get_title = play_title;
-
- return &functions;
-}
+const struct screen_functions screen_playlist = {
+ .init = play_init,
+ .exit = play_exit,
+ .open = play_open,
+ .close = NULL,
+ .resize = play_resize,
+ .paint = play_paint,
+ .update = play_update,
+ .cmd = play_cmd,
+ .get_lw = play_lw,
+ .get_title = play_title,
+};
diff --git a/src/screen_search.c b/src/screen_search.c
index 6e2a0d68ccdd93a749ba1d5e4a7c72599fe48cdd..659070804a44cdb57f6e346588a84324693feab2 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
return 0;
}
-screen_functions_t *
-get_screen_search(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = init;
- functions.exit = quit;
- functions.open = open;
- functions.close = close;
- functions.resize = resize;
- functions.paint = paint;
- functions.update = update;
- functions.cmd = search_cmd;
- functions.get_lw = get_filelist_window;
- functions.get_title = get_title;
-
- return &functions;
-}
-
+const struct screen_functions screen_search = {
+ .init = init,
+ .exit = quit,
+ .open = open,
+ .close = close,
+ .resize = resize,
+ .paint = paint,
+ .update = update,
+ .cmd = search_cmd,
+ .get_lw = get_filelist_window,
+ .get_title = get_title,
+};
#endif /* ENABLE_SEARCH_SCREEN */