From 696d6f4d5c1bc9b36d0402c2393efe62e49392d9 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 3 Dec 2021 14:45:37 -0700 Subject: Use for-each more in gdb There are some loops in gdb that use ARRAY_SIZE (or a wordier equivalent) to loop over a static array. This patch changes some of these to use foreach instead. Regression tested on x86-64 Fedora 34. --- gdb/p-exp.y | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'gdb/p-exp.y') diff --git a/gdb/p-exp.y b/gdb/p-exp.y index f496ce2..e9ebf1f 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1107,28 +1107,28 @@ yylex (void) /* See if it is a special token of length 3. */ if (explen > 2) - for (int i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) - if (strncasecmp (tokstart, tokentab3[i].oper, 3) == 0 - && (!isalpha (tokentab3[i].oper[0]) || explen == 3 + for (const auto &token : tokentab3) + if (strncasecmp (tokstart, token.oper, 3) == 0 + && (!isalpha (token.oper[0]) || explen == 3 || (!isalpha (tokstart[3]) && !isdigit (tokstart[3]) && tokstart[3] != '_'))) { pstate->lexptr += 3; - yylval.opcode = tokentab3[i].opcode; - return tokentab3[i].token; + yylval.opcode = token.opcode; + return token.token; } /* See if it is a special token of length 2. */ if (explen > 1) - for (int i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) - if (strncasecmp (tokstart, tokentab2[i].oper, 2) == 0 - && (!isalpha (tokentab2[i].oper[0]) || explen == 2 + for (const auto &token : tokentab2) + if (strncasecmp (tokstart, token.oper, 2) == 0 + && (!isalpha (token.oper[0]) || explen == 2 || (!isalpha (tokstart[2]) && !isdigit (tokstart[2]) && tokstart[2] != '_'))) { pstate->lexptr += 2; - yylval.opcode = tokentab2[i].opcode; - return tokentab2[i].token; + yylval.opcode = token.opcode; + return token.token; } switch (c = *tokstart) -- cgit v1.1