We know ahead of time the maximum number of outputs we'll be configuring, so just alloc that memory from the get-go, instead of realloc'ing for each new output.
Suggested-by: Pekka Paalanen <[email protected]> Signed-off-by: Bryce Harrington <[email protected]> --- src/main.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/main.c b/src/main.c index 9a8094f..99e5067 100644 --- a/src/main.c +++ b/src/main.c @@ -754,21 +754,6 @@ load_headless_backend(struct weston_compositor *c, char const * backend, } static int -weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config, - struct weston_x11_backend_output_config *output_config) { - struct weston_x11_backend_output_config *new_outputs; - - new_outputs = realloc(config->outputs, (config->num_outputs+1) * - sizeof(struct weston_x11_backend_output_config)); - if (new_outputs == NULL) - return -1; - - config->outputs = new_outputs; - config->outputs[(config->num_outputs)++] = *output_config; - return 0; -} - -static int load_x11_backend(struct weston_compositor *c, char const * backend, int *argc, char **argv, struct weston_config *wc) { @@ -797,6 +782,15 @@ load_x11_backend(struct weston_compositor *c, char const * backend, parse_options(options, ARRAY_LENGTH(options), argc, argv); + if (option_count < 1) { + weston_log("No outputs configured\n"); + return -1; + } + config.outputs = zalloc((option_count+1) * + sizeof(struct weston_x11_backend_output_config)); + if (config.outputs == NULL) + return -1; + section = NULL; while (weston_config_next_section(wc, §ion, §ion_name)) { struct weston_x11_backend_output_config current_output = { 0, }; @@ -842,11 +836,7 @@ load_x11_backend(struct weston_compositor *c, char const * backend, t, current_output.name); free(t); - if (weston_x11_backend_config_append_output_config(&config, ¤t_output) < 0) { - ret = -1; - goto out; - } - + config.outputs[(config.num_outputs)++] = current_output; output_count++; if (option_count && output_count >= option_count) break; @@ -861,13 +851,10 @@ load_x11_backend(struct weston_compositor *c, char const * backend, for (i = output_count; i < option_count; i++) { if (asprintf(default_output.name, "screen%d", i) < 0) { ret = -1; - goto error; - } - - if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) { - ret = -1; goto out; } + + config.outputs[(config.num_outputs)++] = default_output; } config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION; -- 1.9.1 _______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
