Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d52d836
Avoid unnecessary byte[] allocations
stephentoub Aug 19, 2022
1e5020e
Remove unnecessary use of FileStreamOptions
stephentoub Aug 19, 2022
6938c77
Clean up Dispose{Async} implementations
stephentoub Aug 19, 2022
5fa03e9
Clean up unnecessary consts
stephentoub Aug 19, 2022
8dd0ac1
Remove MemoryStream/Encoding.UTF8.GetBytes allocations, unnecessary a…
stephentoub Aug 19, 2022
5be57ad
Avoid string allocations in ReadMagicAttribute
stephentoub Aug 19, 2022
ab71e6c
Avoid allocation in WriteAsOctal
stephentoub Aug 19, 2022
df2d742
Improve handling of octal
stephentoub Aug 19, 2022
c6058bd
Avoid allocation for version string
stephentoub Aug 19, 2022
5756a8c
Removing boxing and char string allocation in GenerateExtendedAttribu…
stephentoub Aug 19, 2022
9539a4a
Fix a couple unnecessary dictionary lookups
stephentoub Aug 19, 2022
74bbc9c
Replace Enum.HasFlag usage
stephentoub Aug 19, 2022
46e0855
Remove allocations from Write{Posix}Name
stephentoub Aug 19, 2022
02ca7da
Replace ArrayPool use with string.Create
stephentoub Aug 19, 2022
f9eb99f
Replace more superfluous ArrayPool usage
stephentoub Aug 19, 2022
add6179
Remove ArrayPool use from System.IO.Compression.ZipFile
stephentoub Aug 20, 2022
6f8cb75
Fix inverted condition
stephentoub Aug 20, 2022
827a588
Use generic math to parse octal
stephentoub Aug 20, 2022
ae21478
Remove allocations from StringReader and string.Split
stephentoub Aug 20, 2022
d6b6727
Remove magic string allocation for Ustar when not V7
stephentoub Aug 20, 2022
480af5c
Remove file name and directory name allocation in GenerateExtendedAtt…
stephentoub Aug 20, 2022
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
Prev Previous commit
Next Next commit
Clean up unnecessary consts
Not a perf thing, just readability.
  • Loading branch information
stephentoub committed Aug 19, 2022
commit 5fa03e9e178ef3aa3eb7606239053670f0586456
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,11 @@ private static byte[] GenerateExtendedAttributeKeyValuePairAsByteArray(byte[] ke
List<byte> bytesList = new();

bytesList.AddRange(finalTotalCharCountBytes);
bytesList.Add(TarHelpers.SpaceChar);
bytesList.Add((byte)' ');
bytesList.AddRange(keyBytes);
bytesList.Add(TarHelpers.EqualsChar);
bytesList.Add((byte)'=');
bytesList.AddRange(valueBytes);
bytesList.Add(TarHelpers.NewLineChar);
bytesList.Add((byte)'\n');

Debug.Assert(bytesList.Count == (realTotalCharCount + suffixByteCount));

Expand All @@ -681,16 +681,16 @@ internal int WriteChecksum(int checksum, Span<byte> buffer)
{
// The checksum field is also counted towards the total sum
// but as an array filled with spaces
checksum += TarHelpers.SpaceChar * 8;
checksum += (byte)' ' * 8;

Span<byte> converted = stackalloc byte[FieldLengths.Checksum];
WriteAsOctal(checksum, converted, 0, converted.Length);

Span<byte> destination = buffer.Slice(FieldLocations.Checksum, FieldLengths.Checksum);

// Checksum field ends with a null and a space
destination[^1] = TarHelpers.SpaceChar; // ' '
destination[^2] = 0; // '\0'
destination[^1] = (byte)' ';
destination[^2] = (byte)'\0';

int i = destination.Length - 3;
int j = converted.Length - 1;
Expand All @@ -704,7 +704,7 @@ internal int WriteChecksum(int checksum, Span<byte> buffer)
}
else
{
destination[i] = TarHelpers.ZeroChar; // Leading zero chars '0'
destination[i] = (byte)'0'; // Leading zero chars
}
i--;
}
Expand Down Expand Up @@ -749,7 +749,7 @@ private static int WriteRightAlignedBytesAndGetChecksum(ReadOnlySpan<byte> bytes
}
else
{
destination[i] = TarHelpers.ZeroChar; // leading zeros
destination[i] = (byte)'0'; // leading zeros
}
checksum += destination[i];
i--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ internal static partial class TarHelpers
internal const short RecordSize = 512;
internal const int MaxBufferLength = 4096;

internal const int ZeroChar = 0x30;
internal const byte SpaceChar = 0x20;
internal const byte EqualsChar = 0x3d;
internal const byte NewLineChar = 0xa;

// Default mode for TarEntry created for a file-type.
private const UnixFileMode DefaultFileMode =
UnixFileMode.UserRead | UnixFileMode.UserWrite |
Expand Down