Skip to content

Commit 3e487c9

Browse files
committed
refactor(BslProcess): Упрощение логики уведомлений исполнителей
Оптимизирована обработка уведомлений исполнителей, заменив циклы на методы массива для повышения читаемости. Удалены временные переменные и улучшена структура кода для лучшей ясности.
1 parent 40bc661 commit 3e487c9

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

src/ScriptEngine/BslProcess.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,25 @@ public BslProcess(int id, ExecutionContext context, IEnumerable<IExecutorProvide
4040
public BslValue Run(BslObjectValue target, IExecutableModule module, BslScriptMethodInfo method, IValue[] arguments)
4141
{
4242
var notifyExecutors = !_isRunning;
43-
List<IExecutorProvider> startedExecutors = null;
44-
45-
try
43+
if (notifyExecutors)
4644
{
47-
if (notifyExecutors)
48-
{
49-
startedExecutors = new List<IExecutorProvider>(_executorProviders.Length);
50-
foreach (var executor in _executorProviders)
51-
{
52-
executor.BeforeProcessStart(this);
53-
startedExecutors.Add(executor);
54-
}
55-
}
45+
Array.ForEach(_executorProviders, e => e.BeforeProcessStart(this));
46+
}
5647

57-
_isRunning = true;
48+
_isRunning = true;
5849

50+
try
51+
{
5952
return _bslExecutorsByModule[module.GetType()](this, target, module, method, arguments);
6053
}
6154
finally
6255
{
6356
if (notifyExecutors)
6457
{
65-
try
66-
{
67-
if (startedExecutors != null)
68-
{
69-
for (var i = startedExecutors.Count - 1; i >= 0; i--)
70-
startedExecutors[i].AfterProcessExit(this);
71-
}
72-
}
73-
finally
74-
{
75-
_isRunning = false;
76-
}
58+
Array.ForEach(_executorProviders, e => e.AfterProcessExit(this));
59+
_isRunning = false;
7760
}
7861
}
7962
}
8063
}
81-
}
64+
}

0 commit comments

Comments
 (0)