Skip to content

Commit

Permalink
compile time optimisation - avoids alloc during analysis
Browse files Browse the repository at this point in the history
was allocating closure all the time
  • Loading branch information
jakubmisek committed Dec 17, 2024
1 parent 45d90fe commit 5b29e58
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Peachpie.CodeAnalysis/Semantics/Model/GlobalSymbolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,27 @@ public IPhpValue ResolveConstant(string name)
foreach (var container in ExtensionContainers)
{
// container.Constant
var match = container.GetMembers(name).Where(IsGlobalConstant).SingleOrDefault();
if (match is IPhpValue phpv) // != null
var members = container.GetMembers(name);
var symbol = (Symbol)null;

// single-or-null
for (var i = 0; i < members.Length; i++)
{
var member = members[i];
if (IsGlobalConstant(member))
{
if (symbol != null)
{
// TODO: report warning
return null; // ambiguity!
}

symbol = member;
}
}

//
if (symbol is IPhpValue phpv)
{
return phpv;
}
Expand Down

0 comments on commit 5b29e58

Please sign in to comment.