Re: mcedit issues



Andrew V. Samoilov wrote:
your last "simplification" remove charset conversion.
Also some people collect all of used glib stuff in our glibcompat.c
to eliminate libglib dependancy, and so you enforce them to import g_string_*()
there.

I would like to apply only this small patch for editcmd.c.

Justification for the use of GString
====================================

I like the data type GString because it is already available in glib-1.2 as well as glib-2.0, it is easy to use, and you don't have to worry about the maximum length of your strings.

from src/subshell.c:694:
    /*
     * Factor 5 because we need \, 0 and 3 other digits per character
     * in the worst case (tcsh and zsh).
     */
    d = ret = g_malloc (5 * strlen (s) + 16);

This could be changed to:

     ret = g_string_new ("");
     ...
     g_string_appendc (ret, 'x');
     g_string_append (ret, "foobar");

Another feature is that getting the string's length will have a time cost of O(1), while the strlen() function has a time cost of O(strlen(s)).

Roland
Index: edit/editcmd.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editcmd.c,v
retrieving revision 1.121
diff -u -p -r1.121 editcmd.c
--- edit/editcmd.c	11 Oct 2004 05:31:29 -0000	1.121
+++ edit/editcmd.c	4 Nov 2004 21:34:18 -0000
@@ -1183,8 +1183,9 @@ edit_replace_prompt (WEdit * edit, char 
 
     GString *label_text = g_string_new (_(" Replace with: "));
     if (*replace_text) {
+        size_t label_len = label_text->len;
         g_string_append (label_text, replace_text);
-        convert_to_display (label_text->str + label_text->len);
+        convert_to_display (label_text->str + label_len);
     }
     quick_widgets[5].text = label_text->str;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]