diff options
author | Marek Olšák <marek.olsak@amd.com> | 2021-10-22 21:02:42 -0400 |
---|---|---|
committer | Marek Olšák <marek.olsak@amd.com> | 2021-10-29 07:19:20 -0400 |
commit | aad903c3f5357697adb4bee82399904d3e78d992 (patch) | |
tree | 5ff7b9e883bd1953d6b0b06602fe31bbfef123de /src/mesa/main | |
parent | 4b67055fef744333c892b8aaab96e765b8d1daef (diff) |
mesa: preparse [ and [0] in gl_resource_name and use it in shader_query.cpp
strrchr is very expensive here.
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13507>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/shader_query.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp index c89c0094bdc..efa46bef990 100644 --- a/src/mesa/main/shader_query.cpp +++ b/src/mesa/main/shader_query.cpp @@ -694,10 +694,8 @@ _mesa_program_resource_find_name(struct gl_shader_program *shProg, if (!_mesa_program_get_resource_name(res, &rname)) continue; - int length_without_array_index = rname.length; - const char *rname_last_square_bracket = strrchr(rname.string, '['); bool found = false; - bool rname_has_array_index_zero = false; + /* From ARB_program_interface_query spec: * * "uint GetProgramResourceIndex(uint program, enum programInterface, @@ -723,12 +721,10 @@ _mesa_program_resource_find_name(struct gl_shader_program *shProg, * array's index is zero and the resulting string length is the same * than the provided name's length. */ - if (rname_last_square_bracket) { - length_without_array_index -= rname_last_square_bracket - rname.string; - rname_has_array_index_zero = - (strcmp(rname_last_square_bracket, "[0]") == 0) && - (length_without_array_index == len); - } + int length_without_array_index = + rname.last_square_bracket >= 0 ? rname.last_square_bracket : rname.length; + bool rname_has_array_index_zero = rname.suffix_is_zero_square_bracketed && + rname.last_square_bracket == len; if (len >= rname.length && strncmp(rname.string, name, rname.length) == 0) found = true; |