Skip to content

Commit b5cb4ed

Browse files
committed
Small speed improvements to the ArrayManager.Add() methode (around 500 ticks, less then a ms, for smaller arrays); Removed unneeded ArrayManager.Copy() methode
1 parent c44f6cd commit b5cb4ed

2 files changed

Lines changed: 13 additions & 48 deletions

File tree

src/WGet.NET/HelperClasses/ArrayManager.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5+
using System;
6+
57
namespace WGetNET.HelperClasses
68
{
79
/// <summary>
@@ -32,8 +34,7 @@ public static T[] Add<T>(T[] inputArray, T value)
3234
return inputArray;
3335
}
3436

35-
//Add a entry to the main array.
36-
inputArray = CopyTo(inputArray, 1);
37+
Array.Resize(ref inputArray, inputArray.Length + 1);
3738

3839
//Add the new line to the new enty in the main array.
3940
#if NETCOREAPP3_1_OR_GREATER
@@ -121,34 +122,6 @@ public static string[] RemoveEmptyEntries(string[] inputArray)
121122
return newArray;
122123
}
123124

124-
/// <summary>
125-
/// Copys a <see langword="array"/> to a new one.
126-
/// </summary>
127-
/// <typeparam name="T">
128-
/// The type of the array.
129-
/// </typeparam>
130-
/// <param name="inputArray">
131-
/// The <see langword="array"/> that should be copyed.
132-
/// </param>
133-
/// <param name="addLengthOf">
134-
/// A <see cref="System.Int32"/> representing a extra length,
135-
/// that should be added to the end of the new array. (DEFAULT = 0)
136-
/// </param>
137-
/// <returns>
138-
/// The new <see langword="array"/>.
139-
/// </returns>
140-
private static T[] CopyTo<T>(T[] inputArray, int addLengthOf = 0)
141-
{
142-
//Copy the input array to the new array.
143-
T[] newArray = new T[inputArray.Length + addLengthOf];
144-
for (int i = 0; i < inputArray.Length; i++)
145-
{
146-
newArray[i] = inputArray[i];
147-
}
148-
149-
return newArray;
150-
}
151-
152125
/// <summary>
153126
/// Copys a <see langword="array"/> to a new one, but ignores the given range.
154127
/// </summary>

src/WGet.NET/XmlDocumentation/WGet.NET.xml

Lines changed: 10 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)