Switch more of toolchain to enumerate/seq (#3137)

These were already used in a few spots, just trying to switch more loops
for consistency and ease of reading.
This commit is contained in:
Jon Ross-Perkins
2023-08-23 00:47:03 +00:00
committed by GitHub
parent 5c2338dbd0
commit 7330e6698c
10 changed files with 39 additions and 44 deletions
@@ -2,6 +2,7 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "llvm/ADT/STLExtras.h"
#include "toolchain/semantics/semantics_context.h"
#include "toolchain/semantics/semantics_node.h"
@@ -30,8 +31,8 @@ auto SemanticsHandleMemberAccessExpression(SemanticsContext& context,
auto refs =
context.semantics_ir().GetNodeBlock(base_type.GetAsStructType());
// TODO: Do we need to optimize this with a lookup table for O(1)?
for (int i = 0; i < static_cast<int>(refs.size()); ++i) {
auto ref = context.semantics_ir().GetNode(refs[i]);
for (auto [i, ref_id] : llvm::enumerate(refs)) {
auto ref = context.semantics_ir().GetNode(ref_id);
if (auto [field_name_id, field_type_id] = ref.GetAsStructTypeField();
name_id == field_name_id) {
context.AddNodeAndPush(