less malloc and memory fragmentation.
authorbarbieri <barbieri>
Wed, 2 Sep 2009 23:11:22 +0000 (23:11 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 2 Sep 2009 23:11:22 +0000 (23:11 +0000)
not that important, but an easy improvement does not hurt.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@42195 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eina_module.c

index 91019f2..9207799 100644 (file)
@@ -84,9 +84,9 @@ static int EINA_MODULE_LOG_DOM = -1;
 
 struct _Eina_Module
 {
-   char *file;
    void *handle;
    int ref;
+   const char file[];
 };
 
 typedef struct _Dir_List_Get_Cb_Data
@@ -291,13 +291,20 @@ eina_module_shutdown(void)
 EAPI Eina_Module *eina_module_new(const char *file)
 {
    Eina_Module *m;
+   size_t len;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
    /* TODO check that the file exists. Update doc too */
 
-   m = malloc(sizeof(Eina_Module));
-   /* TODO add the magic */
-   m->file = strdup(file);
+   len = strlen(file);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(len > 0, NULL);
+
+   m = malloc(sizeof(Eina_Module) + len + 1);
+   if (!m) {
+      ERR("could not malloc(%lu)\n", sizeof(Eina_Module) + len + 1);
+      return NULL;
+   }
+   memcpy((char *)m->file, file, len + 1);
    m->ref = 0;
    m->handle = NULL;
    DBG("m=%p, file=%s\n", m, file);
@@ -327,7 +334,6 @@ EAPI Eina_Bool eina_module_free(Eina_Module *m)
        if (eina_module_unload(m) == EINA_FALSE)
          return EINA_FALSE;
      }
-   free(m->file);
    free(m);
    return EINA_TRUE;
 }