[v2,1/2] Break up complex assignment in cp_lookup_symbol_via_imports
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
In cp_lookup_symbol_via_imports, we have a complex assignment:
...
directive_match = (search_parents
? (startswith (scope, current->import_dest)
&& (len == 0
|| scope[len] == ':'
|| scope[len] == '\0'))
: streq (scope, current->import_dest));
...
Writing it like this makes it:
- harder to comment on parts of the expression, and also
- harder to understand and modify it.
Also, len == 0 makes the startswith redundant, so that part of the expression
can be hoisted. Doing so makes it clear that scope is not compared against in
all cases.
Fix this by breaking this up into three separate assignments:
...
if (search_parents)
{
if (len == 0)
directive_match = 1;
else
directive_match = (startswith (scope, current->import_dest)
&& (scope[len] == ':'
|| scope[len] == '\0'));
}
else
directive_match = streq (scope, current->import_dest);
...
---
gdb/cp-namespace.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
@@ -394,7 +394,6 @@ cp_lookup_symbol_via_imports (const char *scope,
{
struct block_symbol sym = {};
int len;
- int directive_match;
/* All the symbols we found will be kept in this relational map between
the mangled name and the block_symbol found. We do this so that GDB
@@ -425,13 +424,21 @@ cp_lookup_symbol_via_imports (const char *scope,
do not use this directive. */
if (!current->valid_line (boundary_sal.line))
continue;
+
len = strlen (current->import_dest);
- directive_match = (search_parents
- ? (startswith (scope, current->import_dest)
- && (len == 0
- || scope[len] == ':'
- || scope[len] == '\0'))
- : streq (scope, current->import_dest));
+
+ bool directive_match;
+ if (search_parents)
+ {
+ if (len == 0)
+ directive_match = 1;
+ else
+ directive_match = (startswith (scope, current->import_dest)
+ && (scope[len] == ':'
+ || scope[len] == '\0'));
+ }
+ else
+ directive_match = streq (scope, current->import_dest);
/* If the import destination is the current scope or one of its
ancestors then it is applicable. */