From 299d0493b92469818cbb31950aa41164b4acc6ce Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Aug 2021 11:48:36 +0200 Subject: [PATCH] Optimize single undo edit action to not use wrapper --- Source/Editor/Undo/Undo.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Undo/Undo.cs b/Source/Editor/Undo/Undo.cs index 709e21a32..80a5d69a3 100644 --- a/Source/Editor/Undo/Undo.cs +++ b/Source/Editor/Undo/Undo.cs @@ -221,16 +221,20 @@ namespace FlaxEditor var snapshotInstances = (object[])snapshotInstance; if (snapshotInstances == null || snapshotInstances.Length != SnapshotInstances.Length) throw new ArgumentException("Invalid multi undo action objects."); - var actions = new List(); + List actions = null; for (int i = 0; i < snapshotInstances.Length; i++) { var diff = Snapshot[i].Compare(snapshotInstances[i]); if (diff.Count == 0) continue; + if (actions == null) + actions = new List(); actions.Add(new UndoActionObject(diff, ActionString, SnapshotInstances[i])); } - if (actions.Count == 0) + if (actions == null) return null; + if (actions.Count == 1) + return actions[0]; return new MultiUndoAction(actions); } }