Skip to content

Commit 0f00e4d

Browse files
committed
perf: ARK-373 improve fqn lookups in namespaces
1 parent 27d305e commit 0f00e4d

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/arkreactor/Compiler/NameResolution/StaticScope.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <utility>
44
#include <algorithm>
5-
#include <fmt/format.h>
65

76
#include <Ark/Compiler/Common.hpp>
87

@@ -84,8 +83,21 @@ namespace Ark::internal
8483
// If the name wasn't qualified, in the current prefixed namespace, look up for it but by qualifying the name
8584
else if (!starts_with_prefix)
8685
{
87-
const auto it = std::ranges::find(m_vars, fullyQualifiedName(name), &Declaration::name);
88-
const auto it_original = std::ranges::find(m_vars, fullyQualifiedName(name), &Declaration::original_name);
86+
const auto fqn = fullyQualifiedName(name);
87+
88+
auto it = m_vars.end();
89+
auto it_original = m_vars.end();
90+
for (auto j = m_vars.begin(), end = m_vars.end(); j != end; ++j)
91+
{
92+
if (j->name == fqn)
93+
it = j;
94+
if (j->original_name == fqn)
95+
it_original = j;
96+
97+
if (it != end && it_original != end)
98+
break;
99+
}
100+
89101
if ((m_is_glob || hasSymbol(name) || (m_with_prefix && origin_namespace == m_namespace)) && it != m_vars.end())
90102
return *it;
91103
if (!m_symbols.empty() && it_original != m_vars.end())
@@ -100,7 +112,7 @@ namespace Ark::internal
100112
if (auto maybe_decl = scope->get(name, origin_namespace, extensive_lookup); maybe_decl.has_value())
101113
{
102114
// prioritize non-hidden declarations
103-
if ((decl.has_value() && decl.value().name.ends_with(HiddenSymbolSuffix)) || !decl.has_value())
115+
if ((decl.has_value() && decl->name.ends_with(HiddenSymbolSuffix)) || !decl.has_value())
104116
decl = maybe_decl;
105117
}
106118
}

0 commit comments

Comments
 (0)