Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 58b94ec

Browse files
committed
Mitigate memory-leak
1 parent 33086b5 commit 58b94ec

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMDefinition.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ private void ProduceStringArrays(int caret = -1, List<SMFunction> currentFunctio
180180
}
181181
}
182182

183-
public List<ACNode> ProduceACNodes()
183+
public void ProduceACNodes(List<ACNode> nodes)
184184
{
185-
var nodes = new List<ACNode>
186-
{
187-
Capacity = Enums.Count + Structs.Count + ConstVariables.Count + Functions.Count
188-
};
185+
186+
nodes.Clear();
187+
188+
nodes.Capacity = Enums.Count + Structs.Count + ConstVariables.Count + Functions.Count;
189189
nodes.AddRange(ACNode.ConvertFromStringArray(FunctionStrings, true, "▲ "));
190190
nodes.AddRange(ACNode.ConvertFromStringList(TypeStrings, false, "♦ "));
191191
nodes.AddRange(ACNode.ConvertFromStringList(Constants, false, "• "));
@@ -196,8 +196,6 @@ public List<ACNode> ProduceACNodes()
196196

197197
//nodes = nodes.Distinct(new ACNodeEqualityComparer()).ToList(); Methodmaps and Functions can and will be the same.
198198
nodes.Sort((a, b) => string.CompareOrdinal(a.EntryName, b.EntryName));
199-
200-
return nodes;
201199
}
202200

203201
public void MergeDefinitions(SMDefinition def)
@@ -341,9 +339,9 @@ public int GetHashCode(ACNode node)
341339

342340
public class ACNode
343341
{
342+
private string Prefix;
344343
public string EntryName;
345344
public bool IsExecutable;
346-
private string _name;
347345

348346
public static List<ACNode> ConvertFromStringArray(string[] strings, bool executable, string prefix = "")
349347
{
@@ -352,7 +350,7 @@ public static List<ACNode> ConvertFromStringArray(string[] strings, bool executa
352350
for (var i = 0; i < length; ++i)
353351
{
354352
nodeList.Add(
355-
new ACNode {_name = prefix + strings[i], EntryName = strings[i], IsExecutable = executable});
353+
new ACNode {Prefix = prefix, EntryName = strings[i], IsExecutable = executable});
356354
}
357355

358356
return nodeList;
@@ -361,9 +359,9 @@ public static List<ACNode> ConvertFromStringArray(string[] strings, bool executa
361359
public static IEnumerable<ACNode> ConvertFromStringList(IEnumerable<string> strings, bool executable,
362360
string prefix = "", bool addSpace = false)
363361
{
364-
return strings.Select(e => new ACNode {_name = prefix + e, EntryName = e, IsExecutable = executable});
362+
return strings.Select(e => new ACNode {Prefix = prefix, EntryName = e, IsExecutable = executable});
365363
}
366364

367-
public override string ToString() => _name;
365+
public override string ToString() => Prefix + EntryName;
368366
}
369367
}

UI/Components/EditorElement/EditorElementIntellisenseController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public void LoadAutoCompletes()
135135
}
136136

137137
_smDef = Program.Configs[Program.SelectedConfig].GetSMDef();
138-
_acEntries = _smDef.ProduceACNodes();
138+
_acEntries = new List<ACNode>();
139+
_smDef.ProduceACNodes(_acEntries);
139140

140141

141142
AutoCompleteBox.ItemsSource = _acEntries;
@@ -148,10 +149,10 @@ public void LoadAutoCompletes()
148149
/// <param name="smDef"> The SMDefinition </param>
149150
private void InterruptLoadAutoCompletes(SMDefinition smDef)
150151
{
151-
var acNodes = smDef.ProduceACNodes();
152+
smDef.ProduceACNodes(_acEntries);
152153
Dispatcher?.Invoke(() =>
153154
{
154-
_acEntries = acNodes;
155+
_acEntries = _acEntries;
155156
AutoCompleteBox.ItemsSource = _acEntries;
156157
PreProcAutocompleteBox.ItemsSource = PreProcNodes;
157158
_smDef = smDef;
@@ -430,7 +431,6 @@ private bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
430431
}
431432

432433

433-
434434
// If the preprocessor stmt found close the dialog.
435435
if (statement.Length != 0 && PreProcList.Contains(statement.Trim()))
436436
{
@@ -521,6 +521,7 @@ private bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
521521
{
522522
return false;
523523
}
524+
524525
int len = 0;
525526
for (var i = classOffset; i >= 0; --i)
526527
{
@@ -581,7 +582,8 @@ private bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
581582
var match = NewRegex.Match(text.Substring(0, lineOffset));
582583
if (match.Success)
583584
{
584-
var isNodes = ACNode.ConvertFromStringList(_smDef.Methodmaps.Select(e => e.Name), true, "• ").ToList();
585+
var isNodes = ACNode.ConvertFromStringList(_smDef.Methodmaps.Select(e => e.Name), true, "• ")
586+
.ToList();
585587

586588
if (!isNodes.SequenceEqual(_methodACEntries, ISEqualityComparer))
587589
{

0 commit comments

Comments
 (0)