Enlightenment CVS committal

Author  : pfritz
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_text_context.c ewl_text_context.h 


Log Message:
use a shared string for font and font_source in the text context

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text_context.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- ewl_text_context.c  25 Jul 2007 17:01:00 -0000      1.6
+++ ewl_text_context.c  17 Aug 2007 13:41:25 -0000      1.7
@@ -107,12 +107,13 @@
                {
                        if (context_mask & EWL_TEXT_CONTEXT_MASK_FONT)
                        {
-                               IF_FREE(new_tx->font);
-                               new_tx->font = strdup(tx_change->font);
+                               IF_RELEASE(new_tx->font);
+                               new_tx->font = ecore_string_instance(
+                                                       tx_change->font);
 
-                               IF_FREE(new_tx->font_source);
+                               IF_RELEASE(new_tx->font_source);
                                if (tx_change->font_source)
-                                       new_tx->font_source = 
strdup(tx_change->font_source);
+                                       new_tx->font_source = 
ecore_string_instance(tx_change->font_source);
                        }
 
                        if (context_mask & EWL_TEXT_CONTEXT_MASK_SIZE)
@@ -211,7 +212,8 @@
 
        ecore_hash_remove(context_hash, tx);
 
-       IF_FREE(tx->font);
+       IF_RELEASE(tx->font);
+       IF_RELEASE(tx->font_source);
        IF_RELEASE(tx->format);
        FREE(tx);
 
@@ -228,7 +230,7 @@
 void
 ewl_text_context_print(Ewl_Text_Context *tx, const char *indent)
 {
-       char *t, *s;
+       const char *t, *s;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("tx", tx);
@@ -268,11 +270,11 @@
 void
 ewl_text_context_format_string_create(Ewl_Text_Context *ctx)
 {
-       char *format, *t;
+       char *t;
        int pos = 0, i;
        struct 
        {
-               char *key;
+               const char *key;
                char *val;
                int free;
        } fmt[128];
@@ -409,12 +411,11 @@
        fmt[pos].val = t;
        fmt[pos++].free = FALSE;
 
-       t = NEW(char, 128);
 
        fmt[pos].key = "font_source";
        if (ctx->font_source)
        {
-               fmt[pos].val = ctx->font_source;
+               fmt[pos].val = (char *)ctx->font_source;
                fmt[pos++].free = FALSE;
 
                t = strdup(ctx->font);
@@ -424,6 +425,7 @@
                fmt[pos].val = (char *)ewl_theme_path_get();
                fmt[pos++].free = FALSE;
 
+               t = NEW(char, 128);
                snprintf(t, 128, "fonts/%s", ctx->font);
        }
 
@@ -446,21 +448,24 @@
        fmt[pos++].free = TRUE;
 
        /* create the formatting string */
-       format = NEW(char, 2048);
-       strcat(format, "+");
-
-       for (i = 0; i < pos; i ++)
        {
-               strcat(format, fmt[i].key);
-               strcat(format, "=");
-               strcat(format, fmt[i].val);
-               strcat(format, " ");
+               char format[2048];
 
-               if (fmt[i].free) FREE(fmt[i].val);
-       }
+               format[0] = '\0';
+               ecore_strlcat(format, "+", sizeof(format));
 
-       ctx->format = ecore_string_instance(format);
-       FREE(format);
+               for (i = 0; i < pos; i ++)
+               {
+                       ecore_strlcat(format, fmt[i].key, sizeof(format));
+                       ecore_strlcat(format, "=", sizeof(format));
+                       ecore_strlcat(format, fmt[i].val, sizeof(format));
+                       ecore_strlcat(format, " ", sizeof(format));
+
+                       if (fmt[i].free) FREE(fmt[i].val);
+               }
+
+               ctx->format = ecore_string_instance(format);
+       }
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -478,7 +483,7 @@
 
        /* make sure we get our own pointer to the font so it dosen't get
         * free'd behind our back */
-       tx->font = ((old->font) ? strdup(old->font) : NULL);
+       tx->font = ((old->font) ? ecore_string_instance(old->font) : NULL);
        tx->ref_count = 1;
 
        tx->format = ((old->format) ? ecore_string_instance((char 
*)old->format) : NULL);
@@ -518,7 +523,6 @@
 static int
 ewl_text_context_hash_cmp(const void *ctx1, const void *ctx2)
 {
-       unsigned int key1, key2;
        const Ewl_Text_Context *tx1 = ctx1;
        const Ewl_Text_Context *tx2 = ctx2;
 
@@ -527,10 +531,7 @@
 #define KEY_BUILD(c) (c.r | c.g | c.b | c.a)
 #define KEY_COMPARE(k1, k2) if (k1 > k2) goto CTX1_LARGER; else if (k2 > k1) 
goto CTX2_LARGER;
 
-       key1 = ((tx1->font) ? ecore_str_hash(tx1->font) : 0);
-       key2 = ((tx2->font) ? ecore_str_hash(tx2->font) : 0); 
-       KEY_COMPARE(key1, key2);
-
+       KEY_COMPARE(ecore_str_compare(tx1->font, tx2->font), 0);
        KEY_COMPARE(tx1->size, tx2->size);
        KEY_COMPARE(tx1->styles, tx2->styles);
        KEY_COMPARE(KEY_BUILD(tx1->color), KEY_BUILD(tx2->color));
@@ -561,8 +562,12 @@
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("tx", tx);
 
-       tx->font = ((context_mask & EWL_TEXT_CONTEXT_MASK_FONT) ? 
tx_change->font : tx->font);
-       tx->font_source = ((context_mask & EWL_TEXT_CONTEXT_MASK_FONT) ? 
tx_change->font_source : tx->font_source);
+       if (context_mask & EWL_TEXT_CONTEXT_MASK_FONT) {
+               IF_RELEASE(tx->font);
+               IF_RELEASE(tx->font_source);
+               tx->font = ecore_string_instance(tx_change->font);
+               tx->font = ecore_string_instance(tx_change->font);
+       }
        tx->size = ((context_mask & EWL_TEXT_CONTEXT_MASK_SIZE) ? 
tx_change->size : tx->size);
        tx->styles = ((context_mask & EWL_TEXT_CONTEXT_MASK_STYLES) ? 
tx_change->styles : tx->styles),
        tx->align = ((context_mask & EWL_TEXT_CONTEXT_MASK_ALIGN) ? 
tx_change->align : tx->align);
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text_context.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- ewl_text_context.h  25 Apr 2007 15:12:02 -0000      1.1
+++ ewl_text_context.h  17 Aug 2007 13:41:25 -0000      1.2
@@ -20,8 +20,8 @@
  */
 struct Ewl_Text_Context
 {
-       char *font;                             /**< Font name */
-       char *font_source;                      /**< The font source */
+       const char *font;                       /**< Font name */
+       const char *font_source;                /**< The font source */
        unsigned int styles;                    /**< Styles set in this node */
        unsigned int align;                     /**< Text alignment */
        Ewl_Text_Wrap wrap;                     /**< Text wrap setting */



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to