Enlightenment CVS committal

Author  : ningerso
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_text.c 


Log Message:
Change allocation policy to use 4k chunks consistently.
Use a simpler scheme for inserting text.
Set the allocation size to zero after freeing the text.

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -3 -r1.108 -r1.109
--- ewl_text.c  30 Jun 2006 00:46:41 -0000      1.108
+++ ewl_text.c  8 Jul 2006 01:26:45 -0000       1.109
@@ -468,6 +468,12 @@
 
        if (text) len = strlen(text);
 
+       /* Limit the index to be within safe boundaries */
+       if (idx > t->length + 1)
+               idx = t->length + 1;
+       if (idx < 0)
+               idx = 0;
+
        /* setup the cursor position to begin with. If this is the same
         * position as before nothing will change (we'll keep our current
         * pointer */
@@ -477,37 +483,28 @@
        {
                ewl_text_clear(t);
        }
-       else if (!t->text)
-       {
-               t->text = strdup(text);
-               t->length = len;
-               t->total_size = t->length + 1;
-
-               ewl_text_cursor_position_set(t, 0);
-               ewl_text_tree_insert(t, t->cursor_position, t->length);
-               ewl_text_cursor_position_set(t, t->length);
-       }
        else
        {
-               if ((t->length + len + 1) >= t->total_size)
+               int newlen;
+
+               newlen = t->length + len;
+               if ((newlen + 1) >= t->total_size)
                {
                        int extend;
 
-                       extend = len;
-                       if (extend < EWL_TEXT_EXTEND_VAL)
-                               extend = EWL_TEXT_EXTEND_VAL;
+                       /*
+                        * Determine the size in blocks of EWL_TEXT_EXTEND_VAL
+                        */
+                       extend = ((newlen + 1) / EWL_TEXT_EXTEND_VAL);
+                       extend = (extend + 1) * EWL_TEXT_EXTEND_VAL;
 
-                       t->text = realloc(t->text, (t->length + extend + 1) * 
sizeof(char));
-                       t->total_size += extend + 1;
+                       t->text = realloc(t->text, extend * sizeof(char));
+                       t->total_size = extend;
                }
 
-               if (idx == t->length)
-                       strncat(t->text, text, len);
-               else
-               {
+               if (idx < t->length)
                        memmove(t->text + idx + len, t->text + idx, t->length - 
idx);
-                       memcpy(t->text + idx, text, len);
-               }
+               memcpy(t->text + idx, text, len);
                t->length += len;
                t->text[t->length] = '\0';
 
@@ -559,6 +556,7 @@
        else
        {
                IF_FREE(t->text);
+               t->total_size = 0;
                ewl_text_triggers_remove(t);
        }
 



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to