[libcroco-list] Use of g_string_append_printf instead of g_string_append



While adding cr_style_white_space_property_to_string, i remarked that a
lot of time in libcroco g_string_append_printf was used like this:
g_string_append_printf (a_str, "%s", str); // Useless
or like this:
g_string_append_printf (a_str, str); 
Bad if str contains /%./, but where it was, was'nt really a problem.
or like this:
g_string_append_printf (a_str, "(")
g_string_append_printf (a_str, "NULL");

I don't know the overhead of append_printf apart from parsing the string
looking for % parameters, but i think that it's better if
g_string_append and g_string_append_c were used instead.

All the occurences have been converted in my tla archive, i'm attaching
the patch here for review.

@+
* added files

    {arch}/libcroco/libcroco--bdauvergne/libcroco--bdauvergne--0.1/bdauvergne tol-eressea org--2004/patch-log/patch-2

* modified files

--- orig/src/cr-additional-sel.c
+++ mod/src/cr-additional-sel.c
@@ -280,7 +280,7 @@
                         if (cur->content.attr_sel) {
                                 guchar *tmp_str = NULL;
 
-                                g_string_append_printf (str_buf, "[");
+                                g_string_append_c (str_buf, '[');
                                 tmp_str = cr_attr_sel_to_string
                                         (cur->content.attr_sel);
                                 if (tmp_str) {


--- orig/src/cr-attr-sel.c
+++ mod/src/cr-attr-sel.c
@@ -107,7 +107,7 @@
 
         for (cur = a_this; cur; cur = cur->next) {
                 if (cur->prev) {
-                        g_string_append_printf (str_buf, " ");
+                        g_string_append_c (str_buf, ' ');
                 }
 
                 if (cur->name) {
@@ -115,7 +115,7 @@
 
                         name = g_strndup (cur->name->str, cur->name->len);
                         if (name) {
-                                g_string_append_printf (str_buf, "%s", name);
+                                g_string_append (str_buf, name);
                                 g_free (name);
                                 name = NULL;
                         }
@@ -131,17 +131,15 @@
                                         break;
 
                                 case EQUALS:
-                                        g_string_append_printf (str_buf, "=");
+                                        g_string_append_c (str_buf, '=');
                                         break;
 
                                 case INCLUDES:
-                                        g_string_append_printf
-                                                (str_buf, "~=");
+                                        g_string_append (str_buf, "~=");
                                         break;
 
                                 case DASHMATCH:
-                                        g_string_append_printf
-                                                (str_buf, "|=");
+                                        g_string_append (str_buf, "|=");
                                         break;
 
                                 default:


--- orig/src/cr-declaration.c
+++ mod/src/cr-declaration.c
@@ -482,7 +482,7 @@
                                  a_this->property->len);
                 if (str) {
                         cr_utils_dump_n_chars2 (' ', stringue, a_indent);
-                        g_string_append_printf (stringue, "%s", str);
+                        g_string_append (stringue, str);
                         g_free (str);
                         str = NULL;
                 } else
@@ -584,15 +584,15 @@
                                         g_string_append_printf (stringue,
                                                                 "%s;\n", str);
                                 else
-                                        g_string_append_printf (stringue,
-                                                                "%s", str);
+                                        g_string_append (stringue,
+                                                         str);
                         } else {
                                 if (cur->next)
                                         g_string_append_printf (stringue,
                                                                 "%s;", str);
                                 else
-                                        g_string_append_printf (stringue,
-                                                                "%s", str);
+                                        g_string_append (stringue,
+                                                         str);
                         }
                         g_free (str);
                 } else


--- orig/src/cr-fonts.c
+++ mod/src/cr-fonts.c
@@ -40,7 +40,7 @@
         }
 
         if (!a_this) {
-                g_string_append_printf (*a_string, "NULL");
+                g_string_append (*a_string, "NULL");
                 return CR_OK;
         }
 


--- orig/src/cr-pseudo.c
+++ mod/src/cr-pseudo.c
@@ -65,7 +65,7 @@
                 name = g_strndup (a_this->name->str, a_this->name->len);
 
                 if (name) {
-                        g_string_append_printf (str_buf, "%s", name);
+                        g_string_append (str_buf, name);
                         g_free (name);
                         name = NULL;
                 }
@@ -89,12 +89,12 @@
                         name = NULL;
 
                         if (arg) {
-                                g_string_append_printf (str_buf, "%s", arg);
+                                g_string_append (str_buf, arg);
                                 g_free (arg);
                                 arg = NULL;
                         }
 
-                        g_string_append_printf (str_buf, ")");
+                        g_string_append_c (str_buf, ')');
                 }
         }
 


--- orig/src/cr-rgb.c
+++ mod/src/cr-rgb.c
@@ -243,21 +243,19 @@
         if (a_this->is_percentage == TRUE) {
                 g_string_append_printf (str_buf, "%ld", a_this->red);
 
-                g_string_append_c (str_buf, '%');
-                g_string_append_printf (str_buf, ", ");
+                g_string_append (str_buf, "%, ");
 
                 g_string_append_printf (str_buf, "%ld", a_this->green);
-                g_string_append_c (str_buf, '%');;
-                g_string_append_printf (str_buf, ", ");
+                g_string_append (str_buf, "%, ");
 
                 g_string_append_printf (str_buf, "%ld", a_this->blue);
                 g_string_append_c (str_buf, '%');
         } else {
                 g_string_append_printf (str_buf, "%ld", a_this->red);
-                g_string_append_printf (str_buf, ", ");
+                g_string_append (str_buf, ", ");
 
                 g_string_append_printf (str_buf, "%ld", a_this->green);
-                g_string_append_printf (str_buf, ", ");
+                g_string_append (str_buf, ", ");
 
                 g_string_append_printf (str_buf, "%ld", a_this->blue);
         }


--- orig/src/cr-selector.c
+++ mod/src/cr-selector.c
@@ -145,11 +145,10 @@
 
                                 if (tmp_str) {
                                         if (cur->prev)
-                                                g_string_append_printf
-                                                        (str_buf, ", ");
+                                                g_string_append (str_buf, 
+								 ", ");
 
-                                        g_string_append_printf
-                                                (str_buf, "%s", tmp_str);
+                                        g_string_append (str_buf, tmp_str);
 
                                         g_free (tmp_str);
                                         tmp_str = NULL;


--- orig/src/cr-simple-sel.c
+++ mod/src/cr-simple-sel.c
@@ -112,22 +112,22 @@
                         if (str) {
                                 switch (cur->combinator) {
                                 case COMB_WS:
-                                        g_string_append_printf (str_buf, " ");
+                                        g_string_append (str_buf, " ");
                                         break;
 
                                 case COMB_PLUS:
-                                        g_string_append_printf (str_buf, "+");
+                                        g_string_append (str_buf, "+");
                                         break;
 
                                 case COMB_GT:
-                                        g_string_append_printf (str_buf, ">");
+                                        g_string_append (str_buf, ">");
                                         break;
 
                                 default:
                                         break;
                                 }
 
-                                g_string_append_printf (str_buf, "%s", str);
+                                g_string_append (str_buf, str);
                                 g_free (str);
                                 str = NULL;
                         }
@@ -138,8 +138,7 @@
 
                         tmp_str = cr_additional_sel_to_string (cur->add_sel);
                         if (tmp_str) {
-                                g_string_append_printf
-                                        (str_buf, "%s", tmp_str);
+                                g_string_append (str_buf, tmp_str);
                                 g_free (tmp_str);
                                 tmp_str = NULL;
                         }


--- orig/src/cr-statement.c
+++ mod/src/cr-statement.c
@@ -586,25 +586,25 @@
                         cr_selector_to_string (a_this->kind.ruleset->
                                                sel_list);
                 if (tmp_str) {
-                        g_string_append_printf (stringue, "%s", tmp_str);
+                        g_string_append (stringue, tmp_str);
                         g_free (tmp_str);
                         tmp_str = NULL;
                 }
         }
-        g_string_append_printf (stringue, " {\n");
+        g_string_append (stringue, " {\n");
         if (a_this->kind.ruleset->decl_list) {
                 tmp_str = cr_declaration_list_to_string2
                         (a_this->kind.ruleset->decl_list,
                          a_indent + DECLARATION_INDENT_NB, TRUE);
                 if (tmp_str) {
-                        g_string_append_printf (stringue, "%s", tmp_str);
+                        g_string_append (stringue, tmp_str);
                         g_free (tmp_str);
                         tmp_str = NULL;
                 }
-                g_string_append_printf (stringue, "%s", "\n");
+                g_string_append (stringue, "\n");
                 cr_utils_dump_n_chars2 (' ', stringue, a_indent);
         }
-        g_string_append_printf (stringue, "%s", "}");
+        g_string_append (stringue, "}");
         result = stringue->str;
 
         if (stringue) {
@@ -644,17 +644,17 @@
                 if (a_indent)
                         cr_utils_dump_n_chars2 (' ', stringue, 
                                         a_indent);
-                g_string_append_printf (stringue, "@font-face {\n");
+                g_string_append (stringue, "@font-face {\n");
                 tmp_str = cr_declaration_list_to_string2 
                         (a_this->kind.font_face_rule->decl_list,
                          a_indent + DECLARATION_INDENT_NB, TRUE) ;
                 if (tmp_str) {
-                        g_string_append_printf (stringue, "%s"
-                                                ,tmp_str) ;
+                        g_string_append (stringue,
+                                         tmp_str) ;
                         g_free (tmp_str) ;
                         tmp_str = NULL ;
                 }
-                g_string_append_printf (stringue, "\n}");
+                g_string_append (stringue, "\n}");
         }
         if (stringue) {
                 result = stringue->str ;
@@ -721,14 +721,14 @@
         stringue = g_string_new (NULL) ;
 
         cr_utils_dump_n_chars2 (' ', stringue, a_indent) ;
-        g_string_append_printf (stringue, "@page");
+        g_string_append (stringue, "@page");
 
         if (a_this->kind.page_rule->name) {
                 g_string_append_printf 
                         (stringue, " %s",
                          a_this->kind.page_rule->name->str) ;
         } else {
-                g_string_append_printf (stringue, " ");
+                g_string_append (stringue, " ");
         }
         if (a_this->kind.page_rule->pseudo) {
                 g_string_append_printf 
@@ -737,16 +737,16 @@
         }
         if (a_this->kind.page_rule->decl_list) {
                 gchar *str = NULL ;
-                g_string_append_printf (stringue, " {\n");
+                g_string_append (stringue, " {\n");
                 str = cr_declaration_list_to_string2
                         (a_this->kind.page_rule->decl_list,
                          a_indent + DECLARATION_INDENT_NB, TRUE) ;
                 if (str) {
-                        g_string_append_printf (stringue, "%s", str) ;
+                        g_string_append (stringue, str) ;
                         g_free (str) ;
                         str = NULL ;
                 }
-                g_string_append_printf (stringue, "%s", "\n}\n");
+                g_string_append (stringue, "\n}\n");
         }
         result = stringue->str ;
         g_string_free (stringue, FALSE) ;


--- orig/src/cr-style.c
+++ mod/src/cr-style.c
@@ -2002,7 +2002,7 @@
 
         str = g_string_new (NULL);
         cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
-        g_string_append_printf (str, "%s", "NumPropVal {");
+        g_string_append (str, "NumPropVal {");
         tmp_str = cr_num_to_string (&a_prop_val->sv);
         if (!tmp_str) {
                 status = CR_ERROR;
@@ -2019,8 +2019,8 @@
         g_string_append_printf (str, "av: %s ", tmp_str);
         g_free (tmp_str);
         tmp_str = NULL;
-        g_string_append_printf (str, "%s", "}");
-        g_string_append_printf (a_str, "%s", str->str);
+        g_string_append (str, "}");
+        g_string_append (a_str, str->str);
         status = CR_OK;
       cleanup:
 
@@ -2047,7 +2047,7 @@
         str = g_string_new (NULL);
 
         cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
-        g_string_append_printf (str, "RGBPropVal {");
+        g_string_append (str, "RGBPropVal {");
         tmp_str = cr_rgb_to_string (&a_prop_val->sv);
         if (!tmp_str) {
                 status = CR_ERROR;
@@ -2073,8 +2073,8 @@
         g_free (tmp_str);
         tmp_str = NULL;
 
-        g_string_append_printf (str, "}");
-        g_string_append_printf (a_str, "%s", str->str);
+        g_string_append (str, "}");
+        g_string_append (a_str, str->str);
         status = CR_OK;
       cleanup:
 
@@ -2132,7 +2132,7 @@
                 break;
         }
         cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
-        g_string_append_printf (a_str, "%s", str);
+        g_string_append (a_str, str);
         return CR_OK;
 }
 
@@ -2204,7 +2204,7 @@
                 break;
         }
         cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
-        g_string_append_printf (a_str, str);
+        g_string_append (a_str, str);
         return CR_OK;
 
 }
@@ -2237,7 +2237,7 @@
                 str = (gchar *) "unknown static property";
         }
         cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
-        g_string_append_printf (a_str, "%s", str);
+        g_string_append (a_str, str);
         return CR_OK;
 }
 
@@ -2296,7 +2296,7 @@
                 str = *a_str;
         }
         cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
-        g_string_append_printf (str, "style {\n");
+        g_string_append (str, "style {\n");
 
         /*loop over the num_props and to_string() them */
         for (i = NUM_PROP_TOP; i < NB_NUM_PROPS; i++) {
@@ -2310,13 +2310,13 @@
                 if (tmp_str) {
                         g_string_append_printf (str, "%s: ", tmp_str);
                 } else {
-                        g_string_append_printf (str, "%s", "NULL");
+                        g_string_append (str, "NULL");
                 }
                 tmp_str = NULL;
                 cr_style_num_prop_val_to_string (&a_this->num_props[i], str,
                                                  a_nb_indent +
                                                  INTERNAL_INDENT);
-                g_string_append_printf (str, "\n");
+                g_string_append (str, "\n");
         }
         /*loop over the rgb_props and to_string() them all */
         for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) {
@@ -2325,13 +2325,13 @@
                 if (tmp_str) {
                         g_string_append_printf (str, "%s: ", tmp_str);
                 } else {
-                        g_string_append_printf (str, "%s", "NULL: ");
+                        g_string_append (str, "NULL: ");
                 }
                 tmp_str = NULL;
                 cr_style_rgb_prop_val_to_string (&a_this->rgb_props[i], str,
                                                  a_nb_indent +
                                                  INTERNAL_INDENT);
-                g_string_append_printf (str, "\n");
+                g_string_append (str, "\n");
         }
         /*loop over the border_style_props and to_string() them */
         for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) {
@@ -2340,103 +2340,103 @@
                 if (tmp_str) {
                         g_string_append_printf (str, "%s: ", tmp_str);
                 } else {
-                        g_string_append_printf (str, "NULL: ");
+                        g_string_append (str, "NULL: ");
                 }
                 tmp_str = NULL;
                 cr_style_border_style_to_string (a_this->
                                                  border_style_props[i], str,
                                                  0);
-                g_string_append_printf (str, "\n");
+                g_string_append (str, "\n");
         }
         cr_utils_dump_n_chars2 (' ', str, indent);
-        g_string_append_printf (str, "display: ");
+        g_string_append (str, "display: ");
         cr_style_display_type_to_string (a_this->display, str, 0);
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
-        g_string_append_printf (str, "position: ");
+        g_string_append (str, "position: ");
         cr_style_position_type_to_string (a_this->position, str, 0);
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
-        g_string_append_printf (str, "float-type: ");
+        g_string_append (str, "float-type: ");
         cr_style_float_type_to_string (a_this->float_type, str, 0);
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
-        g_string_append_printf (str, "font-family: ");
+        g_string_append (str, "font-family: ");
         tmp_str = cr_font_family_to_string (a_this->font_family, TRUE);
         if (tmp_str) {
-                g_string_append_printf (str, "%s", tmp_str);
+                g_string_append (str, tmp_str);
                 g_free (tmp_str);
                 tmp_str = NULL;
         } else {
-                g_string_append_printf (str, "NULL");
+                g_string_append (str, "NULL");
         }
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = cr_font_size_to_string (a_this->font_size);
         if (tmp_str) {
                 g_string_append_printf (str, "font-size: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-size: NULL");
+                g_string_append (str, "font-size: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = cr_font_size_adjust_to_string (a_this->font_size_adjust);
         if (tmp_str) {
                 g_string_append_printf (str, "font-size-adjust: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-size-adjust: NULL");
+                g_string_append (str, "font-size-adjust: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = (gchar *) cr_font_style_to_string (a_this->font_style);
         if (tmp_str) {
                 g_string_append_printf (str, "font-size: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-size: NULL");
+                g_string_append (str, "font-size: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = (gchar *) cr_font_variant_to_string (a_this->font_variant);
         if (tmp_str) {
                 g_string_append_printf (str, "font-variant: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-variant: NULL");
+                g_string_append (str, "font-variant: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = (gchar *) cr_font_weight_to_string (a_this->font_weight);
         if (tmp_str) {
                 g_string_append_printf (str, "font-weight: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-weight: NULL");
+                g_string_append (str, "font-weight: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, indent);
         tmp_str = (gchar *) cr_font_stretch_to_string (a_this->font_stretch);
         if (tmp_str) {
                 g_string_append_printf (str, "font-stretch: %s", tmp_str);
         } else {
-                g_string_append_printf (str, "font-stretch: NULL");
+                g_string_append (str, "font-stretch: NULL");
         }
         tmp_str = NULL;
-        g_string_append_printf (str, "\n");
+        g_string_append (str, "\n");
 
         cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
-        g_string_append_printf (str, "}");
+        g_string_append (str, "}");
 
         return CR_OK;
 }


--- orig/src/cr-term.c
+++ mod/src/cr-term.c
@@ -299,16 +299,16 @@
 
                 switch (cur->the_operator) {
                 case DIVIDE:
-                        g_string_append_printf (str_buf, " / ");
+                        g_string_append (str_buf, " / ");
                         break;
 
                 case COMMA:
-                        g_string_append_printf (str_buf, ", ");
+                        g_string_append (str_buf, ", ");
                         break;
 
                 case NO_OP:
                         if (cur->prev) {
-                                g_string_append_printf (str_buf, " ");
+                                g_string_append (str_buf, " ");
                         }
                         break;
                 default:
@@ -318,11 +318,11 @@
 
                 switch (cur->unary_op) {
                 case PLUS_UOP:
-                        g_string_append_printf (str_buf, "+");
+                        g_string_append (str_buf, "+");
                         break;
 
                 case MINUS_UOP:
-                        g_string_append_printf (str_buf, "-");
+                        g_string_append (str_buf, "-");
                         break;
 
                 default:
@@ -362,14 +362,13 @@
                                                  ext_content.func_param);
 
                                         if (tmp_str) {
-                                                g_string_append_printf
-                                                        (str_buf,
-                                                         "%s", tmp_str);
+                                                g_string_append (str_buf, 
+								 tmp_str);
                                                 g_free (tmp_str);
                                                 tmp_str = NULL;
                                         }
 
-                                        g_string_append_printf (str_buf, ")");
+                                        g_string_append (str_buf, ")");
                                         g_free (content);
                                         content = NULL;
                                 }
@@ -425,7 +424,7 @@
                         if (cur->content.rgb) {
                                 guchar *tmp_str = NULL;
 
-                                g_string_append_printf (str_buf, "rgb(");
+                                g_string_append (str_buf, "rgb(");
                                 tmp_str = cr_rgb_to_string (cur->content.rgb);
 
                                 if (tmp_str) {
@@ -433,13 +432,13 @@
                                         g_free (tmp_str);
                                         tmp_str = NULL;
                                 }
-                                g_string_append_printf (str_buf, ")");
+                                g_string_append (str_buf, ")");
                         }
 
                         break;
 
                 case TERM_UNICODERANGE:
-                        g_string_append_printf
+                        g_string_append
                                 (str_buf,
                                  "?found unicoderange: dump not supported yet?");
                         break;
@@ -460,9 +459,8 @@
                         break;
 
                 default:
-                        g_string_append_printf (str_buf,
-                                                "%s",
-                                                "Unrecognized Term type");
+                        g_string_append (str_buf,
+                                         "Unrecognized Term type");
                         break;
                 }
         }





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