From e03a8191763bcf1504fa550d0d17881b71ac6760 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 22 Dec 2022 18:57:40 +0200 Subject: [PATCH] Replace usage of Utils.ExtractArrayFromList with Span --- Source/Editor/GUI/EnumComboBox.cs | 3 ++- Source/Editor/ViewportDebugDrawData.cs | 3 ++- Source/Editor/Windows/OutputLogWindow.cs | 5 +++-- Source/Engine/Renderer/Renderer.cs | 3 ++- Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs | 3 ++- Source/Engine/UI/GUI/Common/RichTextBoxBase.cs | 11 ++++++----- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Source/Editor/GUI/EnumComboBox.cs b/Source/Editor/GUI/EnumComboBox.cs index 24f818d0d..fe2326b23 100644 --- a/Source/Editor/GUI/EnumComboBox.cs +++ b/Source/Editor/GUI/EnumComboBox.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors.Elements; using FlaxEditor.Scripting; @@ -170,7 +171,7 @@ namespace FlaxEditor.GUI BuildEntriesDefault(type, _entries, formatMode); var hasTooltips = false; - var entries = Utils.ExtractArrayFromList(_entries); + var entries = CollectionsMarshal.AsSpan(_entries); for (int i = 0; i < _entries.Count; i++) { ref var e = ref entries[i]; diff --git a/Source/Editor/ViewportDebugDrawData.cs b/Source/Editor/ViewportDebugDrawData.cs index a983af168..5c2461a79 100644 --- a/Source/Editor/ViewportDebugDrawData.cs +++ b/Source/Editor/ViewportDebugDrawData.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using FlaxEngine; namespace FlaxEditor @@ -20,7 +21,7 @@ namespace FlaxEditor private int[] _highlightIndicesSet; private Model _highlightTrianglesModel; - internal IntPtr[] ActorsPtrs => Utils.ExtractArrayFromList(_actors); + internal Span ActorsPtrs => CollectionsMarshal.AsSpan(_actors); internal int ActorsCount => _actors.Count; diff --git a/Source/Editor/Windows/OutputLogWindow.cs b/Source/Editor/Windows/OutputLogWindow.cs index 9c8a97f95..a62205bc8 100644 --- a/Source/Editor/Windows/OutputLogWindow.cs +++ b/Source/Editor/Windows/OutputLogWindow.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Xml; @@ -366,7 +367,7 @@ namespace FlaxEditor.Windows // Try to add the line for multi-line logs if (_entries.Count != 0 && !line.StartsWith("======")) { - ref var last = ref Utils.ExtractArrayFromList(_entries)[_entries.Count - 1]; + ref var last = ref CollectionsMarshal.AsSpan(_entries)[_entries.Count - 1]; last.Message += '\n'; last.Message += line; } @@ -471,7 +472,7 @@ namespace FlaxEditor.Windows _output.ErrorStyle.Font.GetFont(); // Generate the output log - var entries = Utils.ExtractArrayFromList(_entries); + Span entries = CollectionsMarshal.AsSpan(_entries); var searchQuery = _searchBox.Text; for (int i = _textBufferCount; i < _entries.Count; i++) { diff --git a/Source/Engine/Renderer/Renderer.cs b/Source/Engine/Renderer/Renderer.cs index 9efe13e75..0fb11af01 100644 --- a/Source/Engine/Renderer/Renderer.cs +++ b/Source/Engine/Renderer/Renderer.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System.Collections.Generic; +using System.Runtime.InteropServices; namespace FlaxEngine { @@ -15,7 +16,7 @@ namespace FlaxEngine /// The custom set of actors to render. If empty, the loaded scenes will be rendered. public static void DrawSceneDepth(GPUContext context, SceneRenderTask task, GPUTexture output, List customActors) { - var temp = Utils.ExtractArrayFromList(customActors); + var temp = CollectionsMarshal.AsSpan(customActors).ToArray(); // FIXME var tempCount = temp.Length; Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), ref temp, ref tempCount); } diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs index c65b7caf0..b3c19365f 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System.Collections.Generic; +using System.Runtime.InteropServices; using FlaxEngine.Utilities; namespace FlaxEngine.GUI @@ -224,7 +225,7 @@ namespace FlaxEngine.GUI private void OnLineAdded(ref ParsingContext context, int lineEnd) { // Calculate size of the line - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); var lineOrigin = textBlocks[context.LineStartTextBlockIndex].Bounds.Location; var lineSize = Float2.Zero; var lineAscender = 0.0f; diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 4f9e20d5d..9d98de6ce 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; namespace FlaxEngine.GUI { @@ -44,7 +45,7 @@ namespace FlaxEngine.GUI /// True if got text block, otherwise false. public bool GetTextBlock(int index, out TextBlock result) { - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); var count = _textBlocks.Count; for (int i = 0; i < count; i++) { @@ -95,7 +96,7 @@ namespace FlaxEngine.GUI public override Float2 GetTextSize() { var count = _textBlocks.Count; - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); var max = Float2.Zero; for (int i = 0; i < count; i++) { @@ -109,7 +110,7 @@ namespace FlaxEngine.GUI public override Float2 GetCharPosition(int index, out float height) { var count = _textBlocks.Count; - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); // Check if text is empty if (count == 0) @@ -181,7 +182,7 @@ namespace FlaxEngine.GUI { location = Float2.Clamp(location, Float2.Zero, _textSize); - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); var count = _textBlocks.Count; for (int i = 0; i < count; i++) { @@ -242,7 +243,7 @@ namespace FlaxEngine.GUI Render2D.PushTransform(Matrix3x3.Translation2D(-_viewOffset)); // Calculate text blocks for drawing - var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocks = CollectionsMarshal.AsSpan(_textBlocks); var textBlocksCount = _textBlocks?.Count ?? 0; var hasSelection = HasSelection; var selection = new TextRange(SelectionLeft, SelectionRight);