From 77a7add50e47ec10b993915c00e572210ce57869 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 20 Sep 2011 19:56:55 +0100 Subject: [PATCH] attributes: optimize validation of tex_coord%d_in names This avoids using sscanf to determine the texture_unit that a tex_coord%d_in attribute name corresponds to since that was showing high on profiles. Instead once we know we have a "tex_coord" name then we can simply use strtoul which is much cheaper and use the returned endptr we get to verify we have a "_in" suffix after the number. Reviewed-by: Neil Roberts --- cogl/cogl-attribute.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c index e89c18e2a..700d05cfd 100644 --- a/cogl/cogl-attribute.c +++ b/cogl/cogl-attribute.c @@ -47,6 +47,7 @@ #include #include +#include /* This isn't defined in the GLES headers */ #ifndef GL_UNSIGNED_INT @@ -163,7 +164,9 @@ validate_cogl_attribute (const char *name, *name_id = COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY; else if (strncmp (name, "tex_coord", strlen ("tex_coord")) == 0) { - if (sscanf (name, "tex_coord%u_in", texture_unit) != 1) + char *endptr; + *texture_unit = strtoul (name + 9, &endptr, 10); + if (strcmp (endptr, "_in") != 0) { g_warning ("Texture coordinate attributes should either be named " "\"cogl_tex_coord\" or named with a texture unit index "