ecore-wayland: Use calloc rather than malloc+memset
authorBryce Harrington <bryce@osg.samsung.com>
Wed, 18 Mar 2015 00:30:32 +0000 (20:30 -0400)
committerChris Michael <cp.michael@samsung.com>
Wed, 18 Mar 2015 00:30:32 +0000 (20:30 -0400)
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 <bryce@osg.samsung.com>
Reviewers: zmike, cedric, devilhorns

Reviewed By: devilhorns

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2182

src/lib/ecore_wayland/ecore_wl.c
src/lib/ecore_wayland/ecore_wl_output.c
src/lib/ecore_wayland/ecore_wl_window.c

index b6e95ce..49d7f6c 100644 (file)
@@ -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");
index 28c430f..412611b 100644 (file)
@@ -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;
 
index 05f3832..8f2f192 100644 (file)
@@ -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;