private static string ExpandEnvironmentVariablesCore(string name)
{
- Span<char> initialBuffer = stackalloc char[128];
- var result = new ValueStringBuilder(initialBuffer);
+ var result = new ValueStringBuilder(stackalloc char[128]);
int lastPos = 0, pos;
while (lastPos < name.Length && (pos = name.IndexOf('%', lastPos + 1)) >= 0)
// https://support.microsoft.com/en-us/help/909264/naming-conventions-in-active-directory-for-computers-domains-sites-and
// https://msdn.microsoft.com/en-us/library/ms679635.aspx
- Span<char> initialBuffer = stackalloc char[40];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[40]);
GetUserName(ref builder);
ReadOnlySpan<char> name = builder.AsSpan();
#endif
// See the comment in UserName
- Span<char> initialBuffer = stackalloc char[40];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[40]);
GetUserName(ref builder);
ReadOnlySpan<char> name = builder.AsSpan();
// Domain names aren't typically long.
// https://support.microsoft.com/en-us/help/909264/naming-conventions-in-active-directory-for-computers-domains-sites-and
- Span<char> initialDomainNameBuffer = stackalloc char[64];
- var domainBuilder = new ValueStringBuilder(initialDomainNameBuffer);
+ var domainBuilder = new ValueStringBuilder(stackalloc char[64]);
uint length = (uint)domainBuilder.Capacity;
// This API will fail to return the domain name without a buffer for the SID.
{
get
{
- Span<char> initialBuffer = stackalloc char[Interop.Kernel32.MAX_PATH];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[Interop.Kernel32.MAX_PATH]);
uint length;
while ((length = Interop.Kernel32.GetCurrentDirectory((uint)builder.Capacity, ref builder.GetPinnableReference())) > builder.Capacity)
private static string ExpandEnvironmentVariablesCore(string name)
{
- Span<char> initialBuffer = stackalloc char[128];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[128]);
uint length;
while ((length = Interop.Kernel32.ExpandEnvironmentStrings(name, ref builder.GetPinnableReference(), (uint)builder.Capacity)) > builder.Capacity)
get
{
// Normally this will be C:\Windows\System32
- Span<char> initialBuffer = stackalloc char[32];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[32]);
uint length;
while ((length = Interop.Kernel32.GetSystemDirectoryW(ref builder.GetPinnableReference(), (uint)builder.Capacity)) > builder.Capacity)
public static string GetTempPath()
{
- Span<char> initialBuffer = stackalloc char[PathInternal.MaxShortPath];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
GetTempPath(ref builder);
// name on disk.
public static string GetTempFileName()
{
- Span<char> initialTempPathBuffer = stackalloc char[PathInternal.MaxShortPath];
- ValueStringBuilder tempPathBuilder = new ValueStringBuilder(initialTempPathBuffer);
+ var tempPathBuilder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
GetTempPath(ref tempPathBuilder);
- Span<char> initialBuffer = stackalloc char[PathInternal.MaxShortPath];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
uint result = Interop.Kernel32.GetTempFileNameW(
ref tempPathBuilder.GetPinnableReference(), "tmp", 0, ref builder.GetPinnableReference());
maxSize++;
}
- Span<char> initialBuffer = stackalloc char[260]; // MaxShortPath on Windows
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[260]); // MaxShortPath on Windows
builder.EnsureCapacity(maxSize);
for (int i = firstComponent; i < paths.Length; i++)
}
maxSize += paths.Length - 1;
- Span<char> initialBuffer = stackalloc char[260]; // MaxShortPath on Windows
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[260]); // MaxShortPath on Windows
builder.EnsureCapacity(maxSize);
for (int i = 0; i < paths.Length; i++)
/// <returns>Normalized path</returns>
internal static string Normalize(string path)
{
- Span<char> initialBuffer = stackalloc char[PathInternal.MaxShortPath];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
// Get the full path
GetFullPathName(path.AsSpan(), ref builder);
/// </remarks>
internal static string Normalize(ref ValueStringBuilder path)
{
- Span<char> initialBuffer = stackalloc char[PathInternal.MaxShortPath];
- var builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
// Get the full path
GetFullPathName(path.AsSpan(terminate: true), ref builder);
if (normalized)
return path;
- Span<char> initialBuffer = stackalloc char[MaxShortPath];
- ValueStringBuilder builder = new ValueStringBuilder(initialBuffer);
+ var builder = new ValueStringBuilder(stackalloc char[MaxShortPath]);
int start = 0;
if (IsDirectorySeparator(path[start]))
/// <param name="rootLength">The length of the root of the given path</param>
internal static string RemoveRelativeSegments(string path, int rootLength)
{
- Span<char> initialBuffer = stackalloc char[260 /* PathInternal.MaxShortPath */];
- ValueStringBuilder sb = new ValueStringBuilder(initialBuffer);
+ var sb = new ValueStringBuilder(stackalloc char[260 /* PathInternal.MaxShortPath */]);
if (RemoveRelativeSegments(path.AsSpan(), rootLength, ref sb))
{
// Api behavior: if newValue is null, instances of oldValue are to be removed.
newValue ??= string.Empty;
- Span<int> initialSpan = stackalloc int[StackallocIntBufferSizeLimit];
- var replacementIndices = new ValueListBuilder<int>(initialSpan);
+ var replacementIndices = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
unsafe
{
return new string[] { this };
}
- Span<int> initialSpan = stackalloc int[StackallocIntBufferSizeLimit];
- var sepListBuilder = new ValueListBuilder<int>(initialSpan);
+ var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
MakeSeparatorList(separators, ref sepListBuilder);
ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
return SplitInternal(separator!, count, options);
}
- Span<int> sepListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
- var sepListBuilder = new ValueListBuilder<int>(sepListInitialSpan);
-
- Span<int> lengthListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
- var lengthListBuilder = new ValueListBuilder<int>(lengthListInitialSpan);
+ var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
+ var lengthListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
MakeSeparatorList(separators!, ref sepListBuilder, ref lengthListBuilder);
ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
private string[] SplitInternal(string separator, int count, StringSplitOptions options)
{
- Span<int> sepListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
- var sepListBuilder = new ValueListBuilder<int>(sepListInitialSpan);
+ var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
MakeSeparatorList(separator, ref sepListBuilder);
ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
private static string? GetDirectoryEntryFullPath(ref Interop.Sys.DirectoryEntry dirent, string currentPath)
{
- Span<char> nameBuffer = stackalloc char[Interop.Sys.DirectoryEntry.NameBufferSize];
- ReadOnlySpan<char> direntName = dirent.GetName(nameBuffer);
+ ReadOnlySpan<char> direntName = dirent.GetName(stackalloc char[Interop.Sys.DirectoryEntry.NameBufferSize]);
if ((direntName.Length == 1 && direntName[0] == '.') ||
(direntName.Length == 2 && direntName[0] == '.' && direntName[1] == '.'))