From 0d14448b4d92d119724a939a304dd25dceff7edf Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 25 Jul 2017 18:25:03 +0200 Subject: [PATCH] Minor optimization of enclose_expression. --- spirv_glsl.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 421002a2..0d835b55 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1822,23 +1822,26 @@ string CompilerGLSL::enclose_expression(const string &expr) need_parens = true; } - uint32_t paren_count = 0; - for (auto c : expr) + if (!need_parens) { - if (c == '(') - paren_count++; - else if (c == ')') + uint32_t paren_count = 0; + for (auto c : expr) { - assert(paren_count); - paren_count--; - } - else if (c == ' ' && paren_count == 0) - { - need_parens = true; - break; + if (c == '(') + paren_count++; + else if (c == ')') + { + assert(paren_count); + paren_count--; + } + else if (c == ' ' && paren_count == 0) + { + need_parens = true; + break; + } } + assert(paren_count == 0); } - assert(paren_count == 0); // If this expression contains any spaces which are not enclosed by parentheses, // we need to enclose it so we can treat the whole string as an expression.