From a2e301db71b93fb5981c6aa3f7988fc220ec5d0b Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Tue, 17 Mar 2015 20:30:32 -0400 Subject: [PATCH] ecore-wayland: Use calloc rather than malloc+memset Summary: In addition to being fewer lines of code, malloc + memset to 0 is slower than calloc. See http://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc Signed-off-by: Bryce Harrington Reviewers: zmike, cedric, devilhorns Reviewed By: devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2182 --- src/lib/ecore_wayland/ecore_wl.c | 4 +--- src/lib/ecore_wayland/ecore_wl_output.c | 4 +--- src/lib/ecore_wayland/ecore_wl_window.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lib/ecore_wayland/ecore_wl.c b/src/lib/ecore_wayland/ecore_wl.c index b6e95cefc0..49d7f6c998 100644 --- a/src/lib/ecore_wayland/ecore_wl.c +++ b/src/lib/ecore_wayland/ecore_wl.c @@ -162,14 +162,12 @@ ecore_wl_init(const char *name) ECORE_WL_EVENT_INTERFACES_BOUND = ecore_event_type_new(); } - if (!(_ecore_wl_disp = malloc(sizeof(Ecore_Wl_Display)))) + if (!(_ecore_wl_disp = calloc(1, sizeof(Ecore_Wl_Display)))) { ERR("Could not allocate memory for Ecore_Wl_Display structure"); goto exit_ecore_disp; } - memset(_ecore_wl_disp, 0, sizeof(Ecore_Wl_Display)); - if (!(_ecore_wl_disp->wl.display = wl_display_connect(name))) { ERR("Could not connect to Wayland display"); diff --git a/src/lib/ecore_wayland/ecore_wl_output.c b/src/lib/ecore_wayland/ecore_wl_output.c index 28c430f4aa..412611b2d8 100644 --- a/src/lib/ecore_wayland/ecore_wl_output.c +++ b/src/lib/ecore_wayland/ecore_wl_output.c @@ -73,9 +73,7 @@ _ecore_wl_output_add(Ecore_Wl_Display *ewd, unsigned int id) LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!(output = malloc(sizeof(Ecore_Wl_Output)))) return; - - memset(output, 0, sizeof(Ecore_Wl_Output)); + if (!(output = calloc(1, sizeof(Ecore_Wl_Output)))) return; output->display = ewd; diff --git a/src/lib/ecore_wayland/ecore_wl_window.c b/src/lib/ecore_wayland/ecore_wl_window.c index 05f38321e4..8f2f192ebe 100644 --- a/src/lib/ecore_wayland/ecore_wl_window.c +++ b/src/lib/ecore_wayland/ecore_wl_window.c @@ -74,14 +74,12 @@ ecore_wl_window_new(Ecore_Wl_Window *parent, int x, int y, int w, int h, int buf LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!(win = malloc(sizeof(Ecore_Wl_Window)))) + if (!(win = calloc(1, sizeof(Ecore_Wl_Window)))) { ERR("Failed to allocate an Ecore Wayland Window"); return NULL; } - memset(win, 0, sizeof(Ecore_Wl_Window)); - win->display = _ecore_wl_disp; win->parent = parent; win->allocation.x = x;