I've attached an updated patch that removed the redundant if's.
Everything else is pretty much the same. So if no one has any objections
in the near future, I'd like to commit it.

On Mon, 2008-12-15 at 10:00 +1100, Carsten Haitzler wrote:
> On Sun, 14 Dec 2008 15:24:06 +0100 Sebastian Dransfeld
> <sebas...@tango.flipp.net> babbled:
> 
> > Viktor Kojouharov wrote:
> > > Hi,
> > > 
> > > I'm trying to bring epsilon into the 21st century with some
> > > eina_stringshare love. The attached patch should convert all epsilon
> > > strings to consts that use eina_stringshare_*. Please review it.
> > 
> > Strings which are probably unique (like paths) should not be 
> > stringshared, not need to stringshare something that wont be shared.
> 
> they probably should be shared. this is one of the big reasons for 
> stringshare.
> why?
> 
> 1. paths are often long (40-100 or more chars)
> 2. there ARE multiple copies. eg:
>    one in the RGBA software engine
>    one in the evas image object
>    one in the "wrapper" smart objects or structs
>    and now multiple instances of that same icon/image on screen at once...
>    ... and possibly others
> 
> so the string is really duplicated a lot and stringshare helps. a lot. i
> highly recommend putting paths to files in strignshare. highly. it was 
> actually
> analysis of all these duplicated file paths for images/icons that first gave
> birth to stringshare.
> 
Index: src/include/Epsilon_Request.h
===================================================================
--- src/include/Epsilon_Request.h	(revision 38207)
+++ src/include/Epsilon_Request.h	(working copy)
@@ -20,8 +20,8 @@
 	unsigned int   size;     /**< Thumbnail size to be generated */
 	unsigned int   format;   /**< Thumbnail format to be generated */
 	unsigned int   status;   /**< Status code of the thumbnail generation */
-	char          *path;     /**< Path to file requiring thumbnail */
-	char          *dest;     /**< Path to generated file, NULL on error */
+	const char    *path;     /**< Path to file requiring thumbnail */
+	const char    *dest;     /**< Path to generated file, NULL on error */
 	void          *data;     /**< Data associated with this thumbnail. */
 	void          *_event;   /**< private, Pointer to Ecore_Event if it existent. */
 };
Index: src/lib/Epsilon.h
===================================================================
--- src/lib/Epsilon.h	(revision 38207)
+++ src/lib/Epsilon.h	(working copy)
@@ -36,10 +36,10 @@
 
 struct _Epsilon
 {
-  char *hash;
-  char *src;
-  char *thumb;
-  char *key;
+  const char *hash;
+  const char *src;
+  const char *thumb;
+  const char *key;
   int w, h;
   int tw, th;
   int tsize;
@@ -49,10 +49,10 @@
 
 struct _Epsilon_Info
 {
-  char *uri;
+  const char *uri;
   unsigned long long int mtime;
   int w, h;
-  char *mimetype;
+  const char *mimetype;
   Epsilon_Exif_Info *eei;
 };
 typedef struct _Epsilon_Info Epsilon_Info;
Index: src/lib/epsilon_thumb.c
===================================================================
--- src/lib/epsilon_thumb.c	(revision 38207)
+++ src/lib/epsilon_thumb.c	(working copy)
@@ -43,6 +43,7 @@
 	/*
 	 * Init required subsystems.
 	 */
+        if (!eina_stringshare_init()) goto init_error;
 	if (!ecore_init()) goto init_error;
 	if (!ecore_ipc_init()) goto con_init_error;
 	if (!epsilon_init()) goto init_error;
@@ -145,9 +146,8 @@
 static void
 epsilon_request_free(Epsilon_Request *thumb)
 {
-	free(thumb->path);
-	if (thumb->dest)
-		free(thumb->dest);
+	eina_stringshare_del(thumb->path);
+        eina_stringshare_del(thumb->dest);
 	free(thumb);
 }
 
@@ -189,13 +189,8 @@
 	 */
 	tb = epsilon_new(thumb->path);
 	epsilon_thumb_size(tb, thumb->size);
-	if (epsilon_exists(tb) == EPSILON_OK) {
-		const char *dest;
-
-		dest = epsilon_thumb_file_get(tb);
-		if (dest)
-			thumb->dest = strdup(dest);
-	}
+	if (epsilon_exists(tb) == EPSILON_OK)
+          thumb->dest = eina_stringshare_add(epsilon_thumb_file_get(tb));
 	epsilon_free(tb);
 
 	return thumb->dest != NULL;
@@ -326,13 +321,13 @@
 
 	thumb = calloc(1, sizeof(Epsilon_Request));
 	if (!thumb)
-		return NULL;
+          return NULL;
 
-	thumb->path = strdup(path);
-	if (!thumb->path) {
-		free(thumb);
-		return NULL;
+	if (!path) {
+             free(thumb);
+             return NULL;
 	}
+	thumb->path = eina_stringshare_add(path);
 	thumb->size = size;
 	thumb->data = data;
 	thumb->format = format;
Index: src/lib/Epsilon.c
===================================================================
--- src/lib/Epsilon.c	(revision 38207)
+++ src/lib/Epsilon.c	(working copy)
@@ -37,10 +37,10 @@
 #include <Edje.h>
 #include <dlfcn.h>
 
-static char *PATH_DIR_LARGE = NULL;
-static char *PATH_DIR_NORMAL = NULL;
-static char *PATH_DIR_CUSTOM = NULL;
-static char *PATH_DIR_FAIL = NULL;
+static const char *PATH_DIR_LARGE = NULL;
+static const char *PATH_DIR_NORMAL = NULL;
+static const char *PATH_DIR_CUSTOM = NULL;
+static const char *PATH_DIR_FAIL = NULL;
 static unsigned LEN_DIR_LARGE = 0;
 static unsigned LEN_DIR_NORMAL = 0;
 static unsigned LEN_DIR_CUSTOM = 0;
@@ -60,7 +60,7 @@
 extern Epsilon_Exif_Info *epsilon_exif_info_get (Epsilon * e);
 
 static int _epsilon_exists_ext(Epsilon *e, const char *ext, char *path, int path_size, time_t *mtime);
-static char *epsilon_hash (const char *file);
+static const char *epsilon_hash (const char *file);
 #ifdef HAVE_PNG_H
 static FILE *_epsilon_open_png_file_reading (const char *filename);
 static int _epsilon_png_write (const char *file, unsigned int * ptr,
@@ -78,8 +78,8 @@
     {
       if (file[0] == '/')
 	{
-	  result = calloc (1, sizeof (Epsilon));
-	  result->src = strdup (file);
+	  result = calloc(1, sizeof(Epsilon));
+	  result->src = eina_stringshare_add(file);
 	  result->tw = THUMB_SIZE_LARGE;
 	  result->th = THUMB_SIZE_LARGE;
 	  result->format = EPSILON_THUMB_FDO;
@@ -98,15 +98,11 @@
 {
   if (e)
     {
-      if (e->key)
-	free (e->key);
-      if (e->hash)
-	free (e->hash);
-      if (e->src)
-	free (e->src);
-      if (e->thumb)
-	free (e->thumb);
-      free (e);
+       eina_stringshare_del(e->key);
+       eina_stringshare_del(e->hash);
+       eina_stringshare_del(e->src);
+       eina_stringshare_del(e->thumb);
+       free (e);
     }
 }
 
@@ -133,6 +129,8 @@
 }
 
 static int epsilon_init_count = 0;
+
+/* XXX: no epsilon_shutdown? */
 int
 epsilon_init (void)
 {
@@ -146,22 +144,23 @@
   char plugin_path[PATH_MAX];
 
   if (epsilon_init_count) return ++epsilon_init_count;
+  eina_stringshare_init();
 
   home = getenv("HOME");
   base_len = snprintf(buf, sizeof(buf), "%s/.thumbnails", home);
   if (!PATH_DIR_LARGE) {
      strncpy(buf + base_len, "/large", PATH_MAX - base_len);
-     PATH_DIR_LARGE = strdup(buf);
+     PATH_DIR_LARGE = eina_stringshare_add(buf);
      LEN_DIR_LARGE = strlen(buf);
   }
   if (!PATH_DIR_NORMAL) {
      strncpy(buf + base_len, "/normal", PATH_MAX - base_len);
-     PATH_DIR_NORMAL = strdup(buf);
+     PATH_DIR_NORMAL = eina_stringshare_add(buf);
      LEN_DIR_NORMAL = strlen(buf);
   }
   if (!PATH_DIR_FAIL) {
      strncpy(buf + base_len, "/fail/epsilon", PATH_MAX - base_len);
-     PATH_DIR_FAIL = strdup(buf);
+     PATH_DIR_FAIL = eina_stringshare_add(buf);
      LEN_DIR_FAIL = strlen(buf);
   }
 
@@ -201,12 +200,8 @@
 {
   if (e)
     {
-      if (e->key)
-	free (e->key);
-      if (key)
-	e->key = strdup (key);
-      else
-	e->key = NULL;
+       eina_stringshare_del(e->key);
+       e->key = eina_stringshare_add(key);
     }
 }
 
@@ -230,10 +225,10 @@
 const char *
 epsilon_file_get (Epsilon * e)
 {
-  char *result = NULL;
+  const char *result = NULL;
   if (e)
     result = e->src;
-  return (result);
+  return result;
 }
 
 const char *
@@ -243,26 +238,26 @@
   char buf[PATH_MAX];
 
   if (!e)
-    return (NULL);
+    return NULL;
   if (e->thumb)
-    return (e->thumb);
+    return e->thumb;
 
   if (_epsilon_exists_ext(e, "jpg", buf, sizeof(buf), &mtime))
     {
-       e->thumb = strdup(buf);
-       return (e->thumb);
+       e->thumb = eina_stringshare_add(buf);
+       return e->thumb;
     }
 #ifdef HAVE_PNG_H
   if (_epsilon_exists_ext(e, "png", buf, sizeof(buf), &mtime))
     {
-       e->thumb = strdup (buf);
-       return (e->thumb);
+       e->thumb = eina_stringshare_add(buf);
+       return e->thumb;
     }
 #endif
-  return (NULL);
+  return NULL;
 }
 
-static char *
+static const char *
 epsilon_hash (const char *file)
 {
   int n;
@@ -287,7 +282,7 @@
       md5out[2 * n + 1] = hex[hash[n] & 0x0f];
     }
   md5out[2 * n] = '\0';
-  return (strdup (md5out));
+  return eina_stringshare_add(md5out);
 }
 
 static Epsilon_Info *
@@ -304,13 +299,11 @@
 {
   if (info)
     {
-      if (info->uri)
-	free (info->uri);
-      if (info->mimetype)
-	free (info->mimetype);
-      if (info->eei)
-	epsilon_exif_info_free (info->eei);
-      free (info);
+       eina_stringshare_del(info->uri);
+       eina_stringshare_del(info->mimetype);
+       if (info->eei)
+         epsilon_exif_info_free(info->eei);
+       free(info);
     }
 }
 
@@ -340,10 +333,8 @@
 	  p->mtime = info.mtime;
 	  p->w = info.w;
 	  p->h = info.h;
-	  if (info.uri)
-	    p->uri = strdup (info.uri);
-	  if (info.mimetype)
-	    p->mimetype = strdup (info.mimetype);
+          p->uri = eina_stringshare_add(info.uri);
+          p->mimetype = eina_stringshare_add(info.mimetype);
 	}
       epeg_close (im);
     }
@@ -388,9 +379,9 @@
 	  if (!strcmp (text.key, "Thumb::Image::Height"))
 	    p->h = atoi (text.text);
 	  if (!strcmp (text.key, "Thumb::URI"))
-	    p->uri = strdup (text.text);
+	    p->uri = eina_stringshare_add(text.text);
 	  if (!strcmp (text.key, "Thumb::Mimetype"))
-	    p->mimetype = strdup (text.text);
+	    p->mimetype = eina_stringshare_add(text.text);
 	}
       /* png_read_end(png_ptr,info_ptr); */
       png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
@@ -446,7 +437,7 @@
 static void
 _epsilon_file_name(unsigned thumb_size, const char *hash, const char *ext, char *path, int path_size)
 {
-   char *dir;
+   const char *dir;
    int dir_len;
 
    if (thumb_size == THUMB_SIZE_LARGE)
@@ -768,10 +759,9 @@
       base_len = snprintf(buf, sizeof(buf), "%s/.thumbnails/", home);
       strncpy(buf + base_len, dir, PATH_MAX - base_len);
 
-      if (PATH_DIR_CUSTOM)
-        free(PATH_DIR_CUSTOM);
+      eina_stringshare_del(PATH_DIR_CUSTOM);
 
-      PATH_DIR_CUSTOM = strdup(buf);
+      PATH_DIR_CUSTOM = eina_stringshare_add(buf);
       LEN_DIR_CUSTOM = strlen(buf);
       ecore_file_mkpath(PATH_DIR_CUSTOM);
     }
Index: configure.ac
===================================================================
--- configure.ac	(revision 38207)
+++ configure.ac	(working copy)
@@ -23,6 +23,8 @@
 version_info=`expr $VMAJ + $VMIN`":$VMIC:$VMIN"
 AC_SUBST(version_info)
 
+PKG_CHECK_MODULES(EINA, [eina-0])
+
 PKG_CHECK_MODULES(EVAS, [evas >= 0.9.9])
 
 PKG_CHECK_MODULES(ECORE, [
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to