Skip to content

Commit

Permalink
optiizing array copying
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Aug 19, 2021
1 parent 30af0a3 commit d04907a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Binary file modified .metals/metals.h2.db
Binary file not shown.
6 changes: 3 additions & 3 deletions .metals/metals.lock.db
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#FileLock
#Mon Jul 12 18:17:00 MSK 2021
server=localhost\:59825
#Fri Aug 20 00:03:35 MSK 2021
server=localhost\:61983
hostName=localhost
method=file
id=17a9b4afbd10ae123e90d5f9833e0743feff1cdb50d
id=17b6039f25a63e082554dea9fe3c8cce6a94cf45c55
19 changes: 16 additions & 3 deletions src/ImTools/ImTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ public static T[] Copy<T>(this T[] items)
for (var i = 0; i < count; ++i)
copy[i] = items[i];
else
Array.Copy(items, copy, count);
Array.Copy(items, 0, copy, 0, count);
return copy;
}

Expand All @@ -1631,7 +1631,7 @@ public static T[] CopyNonEmpty<T>(this T[] items)
for (var i = 0; i < count; ++i)
copy[i] = items[i];
else
Array.Copy(items, copy, count);
Array.Copy(items, 0, copy, 0, count);
return copy;
}

Expand Down Expand Up @@ -2710,10 +2710,23 @@ private static T[] Expand(T[] items)
{
var count = items.Length;
var newItems = new T[count << 1]; // count x 2
Array.Copy(items, 0, newItems, 0, count);
if (count < 6)
for (var i = 0; i < count; ++i)
newItems[i] = items[i];
else
Array.Copy(items, 0, newItems, 0, count);
return newItems;
}

///<summary>Creates the final array out of the list, so that you cannot use after that!</summary>
public T[] BuildArray()
{
var items = Items;
if (Count < items.Length)
Array.Resize(ref items, Count);
return items;
}

/// <inheritdoc />
public override string ToString() =>
$"Count {Count} of {(Count == 0 || Items == null || Items.Length == 0 ? "empty" : "first (" + Items[0] + ") and last (" + Items[Count - 1] + ")")}";
Expand Down

0 comments on commit d04907a

Please sign in to comment.