css: Avoid some allocations
authorMatthias Clasen <mclasen@redhat.com>
Thu, 12 Jan 2023 04:19:30 +0000 (23:19 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 12 Jan 2023 05:12:09 +0000 (00:12 -0500)
Avoid duplicating the function name just
for an error message.

gtk/css/gtkcssparser.c

index 7668bfc70e40fe377699fb14567f1e193f5f15e5..886e84f9529e34fdd7667cb83112d67289d646e1 100644 (file)
@@ -642,13 +642,13 @@ gtk_css_parser_consume_function (GtkCssParser *self,
 {
   const GtkCssToken *token;
   gboolean result = FALSE;
-  char *function_name;
+  char function_name[64];
   guint arg;
 
   token = gtk_css_parser_get_token (self);
   g_return_val_if_fail (gtk_css_token_is (token, GTK_CSS_TOKEN_FUNCTION), FALSE);
 
-  function_name = g_strdup (token->string.string);
+  g_strlcpy (function_name, token->string.string, 64);
   gtk_css_parser_start_block (self);
 
   arg = 0;
@@ -691,7 +691,6 @@ gtk_css_parser_consume_function (GtkCssParser *self,
     }
 
   gtk_css_parser_end_block (self);
-  g_free (function_name);
 
   return result;
 }
@@ -756,7 +755,7 @@ gtk_css_parser_has_integer (GtkCssParser *self)
  * Checks if the next token is a function with the given @name.
  *
  * Returns: %TRUE if the next token is a function with the given @name
- **/
+ */
 gboolean
 gtk_css_parser_has_function (GtkCssParser *self,
                              const char   *name)