[Mesa-dev] [PATCH] glcpp: simplify the check for hexadecimal number

Vlad Golovkin vlad.golovkin.mail at gmail.com
Fri Jun 2 12:37:07 UTC 2017


This will make it possible to remove unnecessary strlen and strncmp
calls.
---
 src/compiler/glsl/glcpp/glcpp-parse.y | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index fe211a0f0b..8cdd4c9d5b 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -450,10 +450,12 @@ control_line_error:
 
 integer_constant:
 	INTEGER_STRING {
-		if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) {
-			$$ = strtoll ($1 + 2, NULL, 16);
-		} else if ($1[0] == '0') {
-			$$ = strtoll ($1, NULL, 8);
+		if ($1[0] == '0') {
+			if ($1[1] == 'x' && $1[2] != '\0') {
+				$$ = strtoll ($1 + 2, NULL, 16);
+			} else {
+				$$ = strtoll ($1, NULL, 8);
+			}
 		} else {
 			$$ = strtoll ($1, NULL, 10);
 		}
-- 
2.11.0



More information about the mesa-dev mailing list