Skip to content

Commit 3035505

Browse files
committed
5.0.2
-Fix major bug in StorageResize
1 parent 6a7c1df commit 3035505

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

Directory.Build.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
<PackageProjectUrl>https://github.com/DevAM-Tools/LargeCollections</PackageProjectUrl>
1616
<RepositoryUrl>https://github.com/DevAM-Tools/LargeCollections</RepositoryUrl>
1717
<PackageReadmeFile>README.md</PackageReadmeFile>
18-
<Version>5.0.1</Version>
19-
<AssemblyVersion>5.0.1</AssemblyVersion>
20-
<FileVersion>5.0.1</FileVersion>
18+
<Version>5.0.2</Version>
19+
<AssemblyVersion>5.0.2</AssemblyVersion>
20+
<FileVersion>5.0.2</FileVersion>
2121
<SignAssembly>False</SignAssembly>
22+
</PropertyGroup>
23+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
2224
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
2325
</PropertyGroup>
2426
</Project>

LargeCollections/LargeArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void Resize(long capacity)
6767
{
6868
return;
6969
}
70-
_Storage.StorageResize(capacity);
70+
StorageExtensions.StorageResize(ref _Storage, capacity);
7171
Count = capacity;
7272
}
7373

LargeCollections/LargeList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public void EnsureRemainingCapacity(long capacity)
835835
[MethodImpl(MethodImplOptions.AggressiveInlining)]
836836
private void Resize(long capacity)
837837
{
838-
_Storage.StorageResize(capacity);
838+
StorageExtensions.StorageResize(ref _Storage, capacity);
839839
Capacity = capacity;
840840
}
841841
}

LargeCollections/StorageExtensions.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,15 @@ internal static void StorageCopyTo<T>(this T[][] source, T[][] target, long sour
453453
[MethodImpl(MethodImplOptions.AggressiveInlining)]
454454
internal static void StorageCopyToArray<T>(this T[][] source, T[] target, long sourceOffset, int targetOffset, int count)
455455
{
456-
long currentCount = 0L;
457-
long currentTargetItemIndex = targetOffset;
456+
int currentCount = 0;
457+
int currentTargetItemIndex = targetOffset;
458458

459459
while (currentCount < count)
460460
{
461461
(int currentSourceStorageIndex, int currentSourceItemIndex) = StorageGetIndex(sourceOffset + currentCount);
462462
T[] currentSourceArray = source[currentSourceStorageIndex];
463463

464-
long elementsToCopyCount = Math.Min(currentSourceArray.Length - currentSourceItemIndex, target.Length - currentTargetItemIndex);
464+
int elementsToCopyCount = Math.Min(currentSourceArray.Length - currentSourceItemIndex, target.Length - currentTargetItemIndex);
465465
elementsToCopyCount = Math.Min(elementsToCopyCount, count - currentCount);
466466

467467
if (elementsToCopyCount <= 0)
@@ -480,24 +480,24 @@ internal static void StorageCopyToArray<T>(this T[][] source, T[] target, long s
480480
[MethodImpl(MethodImplOptions.AggressiveInlining)]
481481
internal static void StorageCopyToSpan<T>(this T[][] source, Span<T> target, long sourceOffset, int count)
482482
{
483-
long currentCount = 0L;
484-
long currentTargetItemIndex = 0L;
483+
int currentCount = 0;
484+
int currentTargetItemIndex = 0;
485485

486486
while (currentCount < count)
487487
{
488488
(int currentSourceStorageIndex, int currentSourceItemIndex) = StorageGetIndex(sourceOffset + currentCount);
489489
T[] currentSourceArray = source[currentSourceStorageIndex];
490490

491-
long elementsToCopyCount = Math.Min(currentSourceArray.Length - currentSourceItemIndex, target.Length - currentTargetItemIndex);
491+
int elementsToCopyCount = Math.Min(currentSourceArray.Length - currentSourceItemIndex, target.Length - currentTargetItemIndex);
492492
elementsToCopyCount = Math.Min(elementsToCopyCount, count - currentCount);
493493

494494
if (elementsToCopyCount <= 0)
495495
{
496496
throw new ArgumentException("No elements to copy. Check source and target arrays and their offsets/counts.");
497497
}
498498

499-
ReadOnlySpan<T> sourceSpan = currentSourceArray.AsSpan(currentSourceItemIndex, (int)elementsToCopyCount);
500-
Span<T> targetSpan = target.Slice((int)currentTargetItemIndex, (int)elementsToCopyCount);
499+
ReadOnlySpan<T> sourceSpan = currentSourceArray.AsSpan(currentSourceItemIndex, elementsToCopyCount);
500+
Span<T> targetSpan = target.Slice(currentTargetItemIndex, elementsToCopyCount);
501501
sourceSpan.CopyTo(targetSpan);
502502

503503
currentCount += elementsToCopyCount;
@@ -516,15 +516,15 @@ internal static void StorageCopyFrom<T>(this T[][] target, T[][] source, long so
516516
internal static void StorageCopyFromArray<T>(this T[][] target, T[] source, int sourceOffset, long targetOffset, int count)
517517
{
518518
long currentCount = 0L;
519-
long currentSourceItemIndex = sourceOffset;
519+
int currentSourceItemIndex = sourceOffset;
520520

521521
while (currentCount < count)
522522
{
523523
(int currentTargetStorageIndex, int currentTargetItemIndex) = StorageGetIndex(targetOffset + currentCount);
524524
T[] currentTargetArray = target[currentTargetStorageIndex];
525525

526-
long elementsToCopyCount = Math.Min(currentTargetArray.Length - currentTargetItemIndex, source.Length - currentSourceItemIndex);
527-
elementsToCopyCount = Math.Min(elementsToCopyCount, count - currentCount);
526+
int elementsToCopyCount = Math.Min(currentTargetArray.Length - currentTargetItemIndex, source.Length - currentSourceItemIndex);
527+
elementsToCopyCount = Math.Min(elementsToCopyCount, count - (int)currentCount);
528528

529529
if (elementsToCopyCount <= 0)
530530
{
@@ -543,23 +543,23 @@ internal static void StorageCopyFromArray<T>(this T[][] target, T[] source, int
543543
internal static void StorageCopyFromSpan<T>(this T[][] target, ReadOnlySpan<T> source, long targetOffset, int count)
544544
{
545545
long currentCount = 0L;
546-
long currentSourceItemIndex = 0L;
546+
int currentSourceItemIndex = 0;
547547

548548
while (currentCount < count)
549549
{
550550
(int currentTargetStorageIndex, int currentTargetItemIndex) = StorageGetIndex(targetOffset + currentCount);
551551
T[] currentTargetArray = target[currentTargetStorageIndex];
552552

553-
long elementsToCopyCount = Math.Min(currentTargetArray.Length - currentTargetItemIndex, source.Length - currentSourceItemIndex);
554-
elementsToCopyCount = Math.Min(elementsToCopyCount, count - currentCount);
553+
int elementsToCopyCount = Math.Min(currentTargetArray.Length - currentTargetItemIndex, source.Length - currentSourceItemIndex);
554+
elementsToCopyCount = Math.Min(elementsToCopyCount, count - (int)currentCount);
555555

556556
if (elementsToCopyCount <= 0)
557557
{
558558
throw new ArgumentException("No elements to copy. Check source and target arrays and their offsets/counts.");
559559
}
560560

561-
ReadOnlySpan<T> sourceSpan = source.Slice((int)currentSourceItemIndex, (int)elementsToCopyCount);
562-
Span<T> targetSpan = currentTargetArray.AsSpan((int)currentTargetItemIndex, (int)elementsToCopyCount);
561+
ReadOnlySpan<T> sourceSpan = source.Slice(currentSourceItemIndex, elementsToCopyCount);
562+
Span<T> targetSpan = currentTargetArray.AsSpan(currentTargetItemIndex, elementsToCopyCount);
563563
sourceSpan.CopyTo(targetSpan);
564564

565565
currentCount += elementsToCopyCount;
@@ -611,7 +611,7 @@ internal static long StorageReadFromStream(this byte[][] target, Stream stream,
611611
}
612612

613613
[MethodImpl(MethodImplOptions.AggressiveInlining)]
614-
internal static void StorageResize<T>(this T[][] array, long capacity)
614+
internal static void StorageResize<T>(ref T[][] array, long capacity)
615615
{
616616
if (capacity < 0L || capacity > Constants.MaxLargeCollectionCount)
617617
{
@@ -629,6 +629,10 @@ internal static void StorageResize<T>(this T[][] array, long capacity)
629629
{
630630
array[i] = new T[Constants.MaxStorageCapacity];
631631
}
632+
else if (array[i].Length < Constants.MaxStorageCapacity)
633+
{
634+
Array.Resize(ref array[i], (int)Constants.MaxStorageCapacity);
635+
}
632636
}
633637

634638
if (newStorageCount > 0)

0 commit comments

Comments
 (0)