Skip to content

Commit f5892f8

Browse files
author
Vyacheslav
committed
perf:
% do nothing if collection not have elements; % don't copy trash
1 parent 12e1e1d commit f5892f8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Src/StackMemoryCollections/GeneratePrimitiveStack.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,12 @@ bool calculateSize
10511051
builder.Append($@"
10521052
public void Copy(in Class.StackOf{typeof(T).Name} destStack)
10531053
{{
1054-
if (destStack.Capacity < Capacity)
1054+
if(Size == 0)
1055+
{{
1056+
return;
1057+
}}
1058+
1059+
if (destStack.Capacity < Size)
10551060
{{
10561061
throw new ArgumentException(""Destination stack not enough capacity"");
10571062
}}
@@ -1060,7 +1065,7 @@ public void Copy(in Class.StackOf{typeof(T).Name} destStack)
10601065
_start,
10611066
destStack.Start,
10621067
destStack.Capacity * {(calculateSize ? $"(nuint)sizeof({typeof(T).Name})" : (sizeOf).ToString())},
1063-
Capacity * {(calculateSize ? $"(nuint)sizeof({typeof(T).Name})" : (sizeOf).ToString())}
1068+
Size * {(calculateSize ? $"(nuint)sizeof({typeof(T).Name})" : (sizeOf).ToString())}
10641069
);
10651070
10661071
destStack.Size = Size;

Src/StackMemoryCollections/GenerateStack.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,12 @@ in string sizeOfStr
10701070
builder.Append($@"
10711071
public void Copy(in {currentType.ContainingNamespace}.Class.StackOf{currentType.Name} destStack)
10721072
{{
1073-
if (destStack.Capacity < Capacity)
1073+
if(Size == 0)
1074+
{{
1075+
return;
1076+
}}
1077+
1078+
if (destStack.Capacity < Size)
10741079
{{
10751080
throw new ArgumentException(""Destination stack not enough capacity"");
10761081
}}
@@ -1079,7 +1084,7 @@ public void Copy(in {currentType.ContainingNamespace}.Class.StackOf{currentType.
10791084
_start,
10801085
destStack.Start,
10811086
destStack.Capacity * {sizeOfStr},
1082-
Capacity * {sizeOfStr}
1087+
Size * {sizeOfStr}
10831088
);
10841089
10851090
destStack.Size = Size;

0 commit comments

Comments
 (0)