2007-09-25 [colin] 3.0.1cvs28
authorColin Leroy <colin@colino.net>
Tue, 25 Sep 2007 17:03:13 +0000 (17:03 +0000)
committerColin Leroy <colin@colino.net>
Tue, 25 Sep 2007 17:03:13 +0000 (17:03 +0000)
* src/codeconv.c
Optimisation: shortcut conv_codeset_strdup
when src_code and dest_code are the same
* src/common/xml.c
* src/common/xml.h
Optimisation: shortcut code conversions when
files are in UTF-8; faster list walking by
using prepend/reverse.

ChangeLog
PATCHSETS
configure.ac
src/codeconv.c
src/common/xml.c
src/common/xml.h

index 16d584750d1fa65d69bcb28ba689426ba022ed46..41edf6343ef878663f7b1fd48d70380da7bc58ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-09-25 [colin]     3.0.1cvs28
+
+       * src/codeconv.c
+               Optimisation: shortcut conv_codeset_strdup
+               when src_code and dest_code are the same
+       * src/common/xml.c
+       * src/common/xml.h
+               Optimisation: shortcut code conversions when
+               files are in UTF-8; faster list walking by
+               using prepend/reverse.
+
 2007-09-25 [holger]    3.0.1cvs27
 
        * src/printing.c
index 730d27c5563afd49123a3e673a858cf400fd31b1..30b7e32983f7867dbeabe8314b662fe2e2f1c72e 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.105.2.111 -r 1.105.2.112 src/prefs_account.c;  cvs diff -u -r 1.52.2.50 -r 1.52.2.51 src/prefs_folder_item.c;  cvs diff -u -r 1.1.2.24 -r 1.1.2.25 src/prefs_quote.c;  cvs diff -u -r 1.8.2.24 -r 1.8.2.25 src/quote_fmt.c;  cvs diff -u -r 1.5.12.11 -r 1.5.12.12 src/quote_fmt.h;  ) > 3.0.1cvs25.patchset
 ( cvs diff -u -r 1.382.2.410 -r 1.382.2.411 src/compose.c;  ) > 3.0.1cvs26.patchset
 ( cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/printing.c;  ) > 3.0.1cvs27.patchset
+( cvs diff -u -r 1.65.2.58 -r 1.65.2.59 src/codeconv.c;  cvs diff -u -r 1.1.4.20 -r 1.1.4.21 src/common/xml.c;  cvs diff -u -r 1.1.4.10 -r 1.1.4.11 src/common/xml.h;  ) > 3.0.1cvs28.patchset
index cb5f2ccb33db1be0ce5f9ee94aa204b95ebee4a7..2889bb494acaf286b722d52fd973d003f78bac2b 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=27
+EXTRA_VERSION=28
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 87081b0e63ead015eedde2677f73ee7a87260849..0b29f5ee2a8d0a80d6d146d42cbfec582cc46c51 100644 (file)
@@ -716,6 +716,9 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
        size_t len;
        CodeConvFunc conv_func;
 
+       if (!strcmp2(src_code, dest_code))
+               return g_strdup(inbuf);
+
        src_code = conv_get_fallback_for_private_encoding(src_code);
        conv_func = conv_get_code_conv_func(src_code, dest_code);
        if (conv_func != conv_noconv) {
index f3dcf67b599402ab43ff6784ff49cff064a3a916..d7763370ab73198aa2f66f430a1e905193e95b77 100644 (file)
@@ -175,8 +175,12 @@ gint xml_get_dtd(XMLFile *file)
                        bufp += 9;
                        extract_quote(bufp, '"');
                        file->encoding = g_strdup(bufp);
-               } else
+                       file->need_codeconv =
+                               strcmp2(bufp, CS_INTERNAL);
+               } else {
                        file->encoding = g_strdup(CS_INTERNAL);
+                       file->need_codeconv = FALSE;
+               }
        } else {
                g_warning("Can't get xml dtd\n");
                return -1;
@@ -230,19 +234,25 @@ gint xml_parse_next_tag(XMLFile *file)
 
        while (*bufp != '\0' && !g_ascii_isspace(*bufp)) bufp++;
        if (*bufp == '\0') {
-               tag_str = conv_codeset_strdup(buf, file->encoding, CS_INTERNAL);
-               if (tag_str) {
-                       tag->tag = XML_STRING_ADD(tag_str);
-                       g_free(tag_str);
+               if (file->need_codeconv) {
+                       tag_str = conv_codeset_strdup(buf, file->encoding, CS_INTERNAL);
+                       if (tag_str) {
+                               tag->tag = XML_STRING_ADD(tag_str);
+                               g_free(tag_str);
+                       } else
+                               tag->tag = XML_STRING_ADD(buf);
                } else
                        tag->tag = XML_STRING_ADD(buf);
                return 0;
        } else {
                *bufp++ = '\0';
-               tag_str = conv_codeset_strdup(buf, file->encoding, CS_INTERNAL);
-               if (tag_str) {
-                       tag->tag = XML_STRING_ADD(tag_str);
-                       g_free(tag_str);
+               if (file->need_codeconv) {
+                       tag_str = conv_codeset_strdup(buf, file->encoding, CS_INTERNAL);
+                       if (tag_str) {
+                               tag->tag = XML_STRING_ADD(tag_str);
+                               g_free(tag_str);
+                       } else
+                               tag->tag = XML_STRING_ADD(buf);
                } else
                        tag->tag = XML_STRING_ADD(buf);
        }
@@ -283,21 +293,26 @@ gint xml_parse_next_tag(XMLFile *file)
 
                g_strchomp(attr_name);
                xml_unescape_str(attr_value);
-               utf8_attr_name = conv_codeset_strdup
-                       (attr_name, file->encoding, CS_INTERNAL);
-               utf8_attr_value = conv_codeset_strdup
-                       (attr_value, file->encoding, CS_INTERNAL);
-               if (!utf8_attr_name)
-                       utf8_attr_name = g_strdup(attr_name);
-               if (!utf8_attr_value)
-                       utf8_attr_value = g_strdup(attr_value);
-
-               attr = xml_attr_new(utf8_attr_name, utf8_attr_value);
+               if (file->need_codeconv) {
+                       utf8_attr_name = conv_codeset_strdup
+                               (attr_name, file->encoding, CS_INTERNAL);
+                       utf8_attr_value = conv_codeset_strdup
+                               (attr_value, file->encoding, CS_INTERNAL);
+                       if (!utf8_attr_name)
+                               utf8_attr_name = g_strdup(attr_name);
+                       if (!utf8_attr_value)
+                               utf8_attr_value = g_strdup(attr_value);
+
+                       attr = xml_attr_new(utf8_attr_name, utf8_attr_value);
+                       g_free(utf8_attr_value);
+                       g_free(utf8_attr_name);
+               } else {
+                       attr = xml_attr_new(attr_name, attr_value);
+               }
                xml_tag_add_attr(tag, attr);
 
-               g_free(utf8_attr_value);
-               g_free(utf8_attr_name);
        }
+       tag->attr = g_list_reverse(tag->attr);
 
        return 0;
 }
@@ -366,6 +381,9 @@ gchar *xml_get_element(XMLFile *file)
                return NULL;
        }
 
+       if (!file->need_codeconv)
+               return str;
+
        new_str = conv_codeset_strdup(str, file->encoding, CS_INTERNAL);
        if (!new_str)
                new_str = g_strdup(str);
@@ -468,7 +486,7 @@ XMLAttr *xml_attr_new_int(const gchar *name, const gint value)
 
 void xml_tag_add_attr(XMLTag *tag, XMLAttr *attr)
 {
-       tag->attr = g_list_append(tag->attr, attr);
+       tag->attr = g_list_prepend(tag->attr, attr);
 }
 
 XMLTag *xml_copy_tag(XMLTag *tag)
@@ -482,6 +500,7 @@ XMLTag *xml_copy_tag(XMLTag *tag)
                attr = xml_copy_attr((XMLAttr *)list->data);
                xml_tag_add_attr(new_tag, attr);
        }
+       tag->attr = g_list_reverse(tag->attr);
 
        return new_tag;
 }
@@ -538,22 +557,13 @@ gint xml_unescape_str(gchar *str)
 
 gint xml_file_put_escape_str(FILE *fp, const gchar *str)
 {
-       const gchar *src_codeset = CS_INTERNAL;
-       const gchar *dest_codeset = CS_INTERNAL;
-       gchar *tmpstr = NULL;
        const gchar *p;
        int result = 0;
        g_return_val_if_fail(fp != NULL, -1);
 
        if (!str) return 0;
 
-       tmpstr = conv_codeset_strdup(str, src_codeset, dest_codeset);
-       if (!tmpstr) {
-               g_warning("xml_file_put_escape_str(): Failed to convert character set.");
-               tmpstr = g_strdup(str);
-       }
-
-       for (p = tmpstr; *p != '\0'; p++) {
+       for (p = str; *p != '\0'; p++) {
                switch (*p) {
                case '<':
                        result = fputs("&lt;", fp);
@@ -575,8 +585,6 @@ gint xml_file_put_escape_str(FILE *fp, const gchar *str)
                }
        }
 
-       g_free(tmpstr);
-       
        return (result == EOF ? -1 : 0);
 }
 
index 4e0af1d3a26e30b1edf4944921e7d6483cabed73..2dd2b33eb60374237af32c9abe08fd9ad9e07a6c 100644 (file)
@@ -57,6 +57,7 @@ struct _XMLFile
 
        gchar *dtd;
        gchar *encoding;
+       gboolean need_codeconv;
 
        GList *tag_stack;
        guint level;