From 1a54978869b510d5b712778ae5e32521459f3791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Schl=C3=BCter?= Date: Fri, 30 Mar 2007 01:54:22 +0200 Subject: [PATCH] symbol.c (gfc_find_gsymbol): Simplify, don't unconditionally descend into all branches. * symbol.c (gfc_find_gsymbol): Simplify, don't unconditionally descend into all branches. From-SVN: r123355 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/symbol.c | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 69364bc3944..ddb515bd995 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2007-03-30 Tobias Schlüter + + * symbol.c (gfc_find_gsymbol): Simplify, don't unconditionally + descend into all branches. + 2007-03-29 Tobias Schlüter * intrinsic.c (conv_name): Let gfc_get_string handle the format. diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 7bf9aecf957..b1c5ea3a316 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -2770,20 +2770,19 @@ gfc_symbol_state(void) { gfc_gsymbol * gfc_find_gsymbol (gfc_gsymbol *symbol, const char *name) { - gfc_gsymbol *s; + int c; if (symbol == NULL) return NULL; - if (strcmp (symbol->name, name) == 0) - return symbol; - s = gfc_find_gsymbol (symbol->left, name); - if (s != NULL) - return s; + while (symbol) + { + c = strcmp (name, symbol->name); + if (!c) + return symbol; - s = gfc_find_gsymbol (symbol->right, name); - if (s != NULL) - return s; + symbol = (c < 0) ? symbol->left : symbol->right; + } return NULL; }