Skip to content

Commit 6d33f2d

Browse files
authored
perf: Remove c_reverse from fullUnresolvedPath (sorbet#10110)
* perf: Remove `c_reverse` from `fullUnresolvedPath` Minor optimization * Preserve the printing order
1 parent a48f830 commit 6d33f2d

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

ast/Trees.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ optional<pair<core::SymbolRef, vector<core::NameRef>>> ConstantLit::fullUnresolv
349349
}
350350
ENFORCE(this->resolutionScopes() != nullptr && !this->resolutionScopes()->empty());
351351

352+
// This list is in reverse order, but that doesn't matter because all we ever use this for is
353+
// for Type hashing, and don't care about the order for that.
352354
vector<core::NameRef> namesFailedToResolve;
353355
auto *nested = this;
354356
{
@@ -374,7 +376,6 @@ optional<pair<core::SymbolRef, vector<core::NameRef>>> ConstantLit::fullUnresolv
374376
}
375377
auto &orig = *nested->original();
376378
namesFailedToResolve.emplace_back(orig.cnst);
377-
absl::c_reverse(namesFailedToResolve);
378379
}
379380
auto prefix = nested->resolutionScopes()->front();
380381
return make_pair(prefix, move(namesFailedToResolve));

core/types/printing.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ string UnresolvedClassType::toStringWithTabs(const GlobalState &gs, int tabs) co
3636

3737
string UnresolvedClassType::show(const GlobalState &gs, ShowOptions options) const {
3838
return fmt::format("{}::{} (unresolved)", this->scope.show(gs, options),
39-
fmt::map_join(this->names, "::", [&](const auto &el) -> string { return el.show(gs); }));
39+
fmt::map_join(this->names.rbegin(), this->names.rend(),
40+
"::", [&](const auto &el) -> string { return el.show(gs); }));
4041
}
4142

4243
string UnresolvedAppliedType::toStringWithTabs(const GlobalState &gs, int tabs) const {

0 commit comments

Comments
 (0)