cssparser: Make _gtk_css_parser_try a macro

We almost always pass a constant string to it, so use a macro and try to
trick the compiler into evaluating the 2(!) strlen() calls at compile
time.
This commit is contained in:
Timm Bäder 2019-01-19 18:32:00 +01:00
parent df1f036a95
commit 7f4b7c48e8
2 changed files with 9 additions and 6 deletions

View File

@ -298,17 +298,18 @@ _gtk_css_parser_skip_whitespace (GtkCssParser *parser)
}
gboolean
_gtk_css_parser_try (GtkCssParser *parser,
const char *string,
gboolean skip_whitespace)
gtk_css_parser_try_len (GtkCssParser *parser,
const char *string,
gsize string_len,
gboolean skip_whitespace)
{
g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
g_return_val_if_fail (string != NULL, FALSE);
if (g_ascii_strncasecmp (parser->data, string, strlen (string)) != 0)
if (g_ascii_strncasecmp (parser->data, string, string_len) != 0)
return FALSE;
parser->data += strlen (string);
parser->data += string_len;
if (skip_whitespace)
_gtk_css_parser_skip_whitespace (parser);

View File

@ -66,8 +66,10 @@ gboolean _gtk_css_parser_is_string (GtkCssParser *parser
* however is fine to call if you dont know yet if the token is a foo or a bar,
* you can _try_bar() if try_foo() failed.
*/
gboolean _gtk_css_parser_try (GtkCssParser *parser,
#define _gtk_css_parser_try(p, s, skip) (gtk_css_parser_try_len (p, s, strlen(s), skip))
gboolean gtk_css_parser_try_len (GtkCssParser *parser,
const char *string,
gsize string_len,
gboolean skip_whitespace);
char * _gtk_css_parser_try_ident (GtkCssParser *parser,
gboolean skip_whitespace);