diff options
author | Robert Bragg <robert@linux.intel.com> | 2011-09-20 19:56:55 +0100 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2011-09-21 15:50:13 +0100 |
commit | 77a7add50e47ec10b993915c00e572210ce57869 (patch) | |
tree | 905937898adf850a236cdab4b51dacc9d62ad48c | |
parent | d739892a5cf08084835795337b4444f1678ba8c8 (diff) | |
download | cogl-77a7add50e47ec10b993915c00e572210ce57869.tar.gz |
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 <neil@linux.intel.com>
-rw-r--r-- | cogl/cogl-attribute.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c index e89c18e2..700d05cf 100644 --- a/cogl/cogl-attribute.c +++ b/cogl/cogl-attribute.c @@ -47,6 +47,7 @@ #include <string.h> #include <stdio.h> +#include <stdlib.h> /* 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 " |