[gtk/wip/baedert/widgetview: 3/6] cssparser: Make _gtk_css_parser_try a macro
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/widgetview: 3/6] cssparser: Make _gtk_css_parser_try a macro
- Date: Wed, 23 Jan 2019 16:18:04 +0000 (UTC)
commit cd4712380b42c2ae66536d059c1acbb0d1842ac5
Author: Timm Bäder <mail baedert org>
Date: Sat Jan 19 18:32:00 2019 +0100
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.
gtk/gtkcssparser.c | 11 ++++++-----
gtk/gtkcssparserprivate.h | 4 +++-
2 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index a840d9fbbd..43d6699d03 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -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);
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 5bc2ad691b..3fb30f9136 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -66,8 +66,10 @@ gboolean _gtk_css_parser_is_string (GtkCssParser *parser
* however is fine to call if you don’t 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]