Skip to content

Commit 4e3b160

Browse files
Avoid memory allocations when retrieving OverloadGroupNames (#370)
1 parent 352338d commit 4e3b160

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/UiPath.Workflow.Runtime/RuntimeArgument.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ namespace System.Activities;
1212
public sealed class RuntimeArgument : LocationReference
1313
{
1414
private static InternalEvaluationOrderComparer evaluationOrderComparer;
15+
private static readonly ReadOnlyCollection<string> emptyOverloadGroups = new(Array.Empty<string>());
16+
1517
private Argument _boundArgument;
1618
private readonly PropertyDescriptor _bindingProperty;
1719
private readonly object _bindingPropertyOwner;
1820
private List<string> _overloadGroupNames;
21+
private ReadOnlyCollection<string> _overloadGroupNamesReadOnly;
1922
private int _cacheId;
2023
private readonly string _name;
2124
private uint _nameHash;
@@ -86,8 +89,19 @@ public ReadOnlyCollection<string> OverloadGroupNames
8689
{
8790
get
8891
{
89-
_overloadGroupNames ??= new List<string>(0);
90-
return new ReadOnlyCollection<string>(_overloadGroupNames);
92+
if (_overloadGroupNamesReadOnly == null)
93+
{
94+
if (_overloadGroupNames == null || _overloadGroupNames.Count == 0)
95+
{
96+
_overloadGroupNamesReadOnly = emptyOverloadGroups;
97+
}
98+
else
99+
{
100+
_overloadGroupNamesReadOnly = new ReadOnlyCollection<string>(_overloadGroupNames);
101+
}
102+
}
103+
104+
return _overloadGroupNamesReadOnly;
91105
}
92106
}
93107

0 commit comments

Comments
 (0)