[Mesa-dev] glsl: Do not call lhs->variable_referenced() multiple times

Submitted by Iago Toral Quiroga on May 9, 2014, 6:50 a.m.

Details

Message ID 1399618203-21617-1-git-send-email-itoral@igalia.com
State Accepted
Headers show

Not browsing as part of any series.

Commit Message

Iago Toral Quiroga May 9, 2014, 6:50 a.m.
Instead take the result from the first call and use it where needed.
---
 src/glsl/ast_to_hir.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 7516c33..0128b3f 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -792,25 +792,24 @@  do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
    ir_variable *lhs_var = lhs->variable_referenced();
    if (lhs_var)
       lhs_var->data.assigned = true;
 
    if (!error_emitted) {
       if (non_lvalue_description != NULL) {
          _mesa_glsl_error(&lhs_loc, state,
                           "assignment to %s",
                           non_lvalue_description);
          error_emitted = true;
-      } else if (lhs->variable_referenced() != NULL
-                 && lhs->variable_referenced()->data.read_only) {
+      } else if (lhs_var != NULL && lhs_var->data.read_only) {
          _mesa_glsl_error(&lhs_loc, state,
                           "assignment to read-only variable '%s'",
-                          lhs->variable_referenced()->name);
+                          lhs_var->name);
          error_emitted = true;
       } else if (lhs->type->is_array() &&
                  !state->check_version(120, 300, &lhs_loc,
                                        "whole array assignment forbidden")) {
          /* From page 32 (page 38 of the PDF) of the GLSL 1.10 spec:
           *
           *    "Other binary or unary expressions, non-dereferenced
           *     arrays, function names, swizzles with repeated fields,
           *     and constants cannot be l-values."
           *

Comments

On 05/08/2014 11:50 PM, Iago Toral Quiroga wrote:
> Instead take the result from the first call and use it where needed.
> ---
>  src/glsl/ast_to_hir.cpp | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 7516c33..0128b3f 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -792,25 +792,24 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
>     ir_variable *lhs_var = lhs->variable_referenced();
>     if (lhs_var)
>        lhs_var->data.assigned = true;
>  
>     if (!error_emitted) {
>        if (non_lvalue_description != NULL) {
>           _mesa_glsl_error(&lhs_loc, state,
>                            "assignment to %s",
>                            non_lvalue_description);
>           error_emitted = true;
> -      } else if (lhs->variable_referenced() != NULL
> -                 && lhs->variable_referenced()->data.read_only) {
> +      } else if (lhs_var != NULL && lhs_var->data.read_only) {
>           _mesa_glsl_error(&lhs_loc, state,
>                            "assignment to read-only variable '%s'",
> -                          lhs->variable_referenced()->name);
> +                          lhs_var->name);
>           error_emitted = true;
>        } else if (lhs->type->is_array() &&
>                   !state->check_version(120, 300, &lhs_loc,
>                                         "whole array assignment forbidden")) {
>           /* From page 32 (page 38 of the PDF) of the GLSL 1.10 spec:
>            *
>            *    "Other binary or unary expressions, non-dereferenced
>            *     arrays, function names, swizzles with repeated fields,
>            *     and constants cannot be l-values."
>            *
> 

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>

By the way, if you'd like to apply for push access, the procedure is
documented here:

http://www.freedesktop.org/wiki/AccountRequests/