Replace usage of Utils.ExtractArrayFromList with Span

This commit is contained in:
2022-12-22 18:57:40 +02:00
parent 6a41ab0b6d
commit e03a819176
6 changed files with 17 additions and 11 deletions

View File

@@ -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];

View File

@@ -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<IntPtr> ActorsPtrs => CollectionsMarshal.AsSpan(_actors);
internal int ActorsCount => _actors.Count;

View File

@@ -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<Entry> entries = CollectionsMarshal.AsSpan(_entries);
var searchQuery = _searchBox.Text;
for (int i = _textBufferCount; i < _entries.Count; i++)
{

View File

@@ -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
/// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param>
public static void DrawSceneDepth(GPUContext context, SceneRenderTask task, GPUTexture output, List<Actor> 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);
}

View File

@@ -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;

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace FlaxEngine.GUI
{
@@ -44,7 +45,7 @@ namespace FlaxEngine.GUI
/// <returns>True if got text block, otherwise false.</returns>
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);