tgsi/text: add str_match_format helper function
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 28 Apr 2016 22:07:44 +0000 (17:07 -0500)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 29 Apr 2016 16:39:51 +0000 (11:39 -0500)
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/gallium/auxiliary/tgsi/tgsi_text.c

index 3f5ef05109dd4497d4d3f75532f922d2f3d8cbfc..26e7c8f31659e53fbca8a8196f7847fccab75843 100644 (file)
@@ -119,6 +119,24 @@ static boolean str_match_nocase_whole( const char **pcur, const char *str )
    return FALSE;
 }
 
+/* Return the format corresponding to the name at *pcur.
+ * Returns -1 if there is no format name.
+ *
+ * On success, the pointer to the string is moved to the end of the read format
+ * name.
+ */
+static int str_match_format(const char **pcur)
+{
+   for (unsigned i = 0; i < PIPE_FORMAT_COUNT; i++) {
+      const struct util_format_description *desc =
+         util_format_description(i);
+      if (desc && str_match_nocase_whole(pcur, desc->name)) {
+         return i;
+      }
+   }
+   return -1;
+}
+
 /* Eat zero or more whitespaces.
  */
 static void eat_opt_white( const char **pcur )
@@ -1302,16 +1320,11 @@ static boolean parse_declaration( struct translate_ctx *ctx )
                decl.Image.Writable = 1;
 
             } else {
-               for (i = 0; i < PIPE_FORMAT_COUNT; i++) {
-                  const struct util_format_description *desc =
-                     util_format_description(i);
-                  if (desc && str_match_nocase_whole(&cur2, desc->name)) {
-                     decl.Image.Format = i;
-                     break;
-                  }
-               }
-               if (i == PIPE_FORMAT_COUNT)
+               int format = str_match_format(&cur2);
+               if (format < 0)
                   break;
+
+               decl.Image.Format = format;
             }
             cur = cur2;
             eat_opt_white(&cur2);