[cogl/wip/for-cairo-cogl: 10/12] attributes: optimize validation of tex_coord%d_in names



commit 35041341096f7b106c6a4492df03d577bb8ebca2
Author: Robert Bragg <robert linux intel com>
Date:   Tue Sep 20 19:56:55 2011 +0100

    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.

 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 e89c18e..700d05c 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 "



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]