Skip to content

[gardening] Reduce indentation by using early exits increasing readability #12336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2891,29 +2891,37 @@ ID SILPrintContext::getID(const SILNode *node) {
// Lazily initialize the instruction -> ID mapping.
if (ValueToIDMap.empty())
F->numberValues(ValueToIDMap);
} else {
setContext(BB);
// Lazily initialize the instruction -> ID mapping.
if (ValueToIDMap.empty()) {
unsigned idx = 0;
for (auto &I : *BB) {
// Give the instruction itself the next ID.
ValueToIDMap[&I] = idx;

// If there are no results, make sure we don't reuse that ID.
auto results = I.getResults();
if (results.empty()) {
idx++;

// Otherwise, assign all of the results an index. Note that
// we'll assign the same ID to both the instruction and the
// first result.
} else {
for (auto result : results) {
ValueToIDMap[result] = idx++;
}
}
}
ID R = {ID::SSAValue, ValueToIDMap[node]};
return R;
}

setContext(BB);

// Check if we have initialized our ValueToIDMap yet. If we have, just use
// that.
if (!ValueToIDMap.empty()) {
ID R = {ID::SSAValue, ValueToIDMap[node]};
return R;
}

// Otherwise, initialize the instruction -> ID mapping cache.
unsigned idx = 0;
for (auto &I : *BB) {
// Give the instruction itself the next ID.
ValueToIDMap[&I] = idx;

// If there are no results, make sure we don't reuse that ID.
auto results = I.getResults();
if (results.empty()) {
idx++;
continue;
}

// Otherwise, assign all of the results an index. Note that
// we'll assign the same ID to both the instruction and the
// first result.
for (auto result : results) {
ValueToIDMap[result] = idx++;
}
}

Expand Down