Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Polyfill/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,28 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
// Grow geometrically, as List<T> does. Setting the capacity to exactly count would reallocate
// on every call when the count is raised a little at a time.
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}

if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}

if (grown < count)
{
grown = count;
}

list.Capacity = (int) grown;
}

for (var index = current; index < count; index++)
Expand Down
23 changes: 21 additions & 2 deletions src/Polyfill/CollectionsMarshalSetCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,28 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
// Grow geometrically, as List<T> does. Setting the capacity to exactly count would reallocate
// on every call when the count is raised a little at a time.
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}

if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}

if (grown < count)
{
grown = count;
}

list.Capacity = (int) grown;
}

for (var index = current; index < count; index++)
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net461/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net462/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net47/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net471/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net472/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net48/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net481/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net5.0/CollectionsMarshalSetCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net6.0/CollectionsMarshalSetCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/net7.0/CollectionsMarshalSetCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/netcoreapp2.0/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/netcoreapp2.1/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Split/netcoreapp2.2/CollectionsMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ public static void SetCount<T>(List<T> list, int count)
}
else if (count > current)
{
if (list.Capacity < count)
var capacity = list.Capacity;
if (capacity < count)
{
list.Capacity = count;
long grown = 4;
if (capacity != 0)
{
grown = 2L * capacity;
}
if (grown > 0X7FEFFFFF)
{
grown = 0X7FEFFFFF;
}
if (grown < count)
{
grown = count;
}
list.Capacity = (int) grown;
}
for (var index = current; index < count; index++)
{
Expand Down
Loading
Loading