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
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private static bool shouldUnsetMode(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void WriteToConsole(char c, bool transcribeResult)
{
ReadOnlySpan<char> value = stackalloc char[1] { c };
ReadOnlySpan<char> value = [c];
WriteToConsole(value, transcribeResult);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public override
void
Write(char c)
{
ReadOnlySpan<char> c1 = stackalloc char[1] { c };
_ui.WriteToConsole(c1, transcribeResult: true);
ReadOnlySpan<char> value = [c];
_ui.WriteToConsole(value, transcribeResult: true);
}

public override
Expand Down
40 changes: 22 additions & 18 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,25 +637,29 @@ public string GetModeString()
return DirectoryOwnerFullGroupReadExecOtherReadExec;
}

Span<char> modeCharacters = stackalloc char[10];
modeCharacters[0] = itemTypeTable[ItemType];
bool isExecutable;

UnixFileMode modeInfo = (UnixFileMode)Mode;
modeCharacters[1] = modeInfo.HasFlag(UnixFileMode.UserRead) ? CanRead : NoPerm;
modeCharacters[2] = modeInfo.HasFlag(UnixFileMode.UserWrite) ? CanWrite : NoPerm;
isExecutable = modeInfo.HasFlag(UnixFileMode.UserExecute);
modeCharacters[3] = modeInfo.HasFlag(UnixFileMode.SetUser) ? (isExecutable ? SetAndExec : SetAndNotExec) : (isExecutable ? CanExecute : NoPerm);

modeCharacters[4] = modeInfo.HasFlag(UnixFileMode.GroupRead) ? CanRead : NoPerm;
modeCharacters[5] = modeInfo.HasFlag(UnixFileMode.GroupWrite) ? CanWrite : NoPerm;
isExecutable = modeInfo.HasFlag(UnixFileMode.GroupExecute);
modeCharacters[6] = modeInfo.HasFlag(UnixFileMode.SetGroup) ? (isExecutable ? SetAndExec : SetAndNotExec) : (isExecutable ? CanExecute : NoPerm);

modeCharacters[7] = modeInfo.HasFlag(UnixFileMode.OtherRead) ? CanRead : NoPerm;
modeCharacters[8] = modeInfo.HasFlag(UnixFileMode.OtherWrite) ? CanWrite : NoPerm;
isExecutable = modeInfo.HasFlag(UnixFileMode.OtherExecute);
modeCharacters[9] = modeInfo.HasFlag(UnixFileMode.StickyBit) ? (isExecutable ? StickyAndExec : StickyAndNotExec) : (isExecutable ? CanExecute : NoPerm);

Span<char> modeCharacters = [
itemTypeTable[ItemType],

modeInfo.HasFlag(UnixFileMode.UserRead) ? CanRead : NoPerm,
modeInfo.HasFlag(UnixFileMode.UserWrite) ? CanWrite : NoPerm,
modeInfo.HasFlag(UnixFileMode.SetUser) ?
(modeInfo.HasFlag(UnixFileMode.UserExecute) ? SetAndExec : SetAndNotExec) :
(modeInfo.HasFlag(UnixFileMode.UserExecute) ? CanExecute : NoPerm),

modeInfo.HasFlag(UnixFileMode.GroupRead) ? CanRead : NoPerm,
modeInfo.HasFlag(UnixFileMode.GroupWrite) ? CanWrite : NoPerm,
modeInfo.HasFlag(UnixFileMode.SetGroup) ?
(modeInfo.HasFlag(UnixFileMode.GroupExecute) ? SetAndExec : SetAndNotExec) :
(modeInfo.HasFlag(UnixFileMode.GroupExecute) ? CanExecute : NoPerm),

modeInfo.HasFlag(UnixFileMode.OtherRead) ? CanRead : NoPerm,
modeInfo.HasFlag(UnixFileMode.OtherWrite) ? CanWrite : NoPerm,
modeInfo.HasFlag(UnixFileMode.StickyBit) ?
(modeInfo.HasFlag(UnixFileMode.OtherExecute) ? StickyAndExec : StickyAndNotExec) :
(modeInfo.HasFlag(UnixFileMode.OtherExecute) ? CanExecute : NoPerm),
];

return new string(modeCharacters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static string GetDosDeviceForNetworkPath(char deviceName)
#endif

Span<char> buffer = stackalloc char[StartLength + 1];
Span<char> fullDeviceName = stackalloc char[3] { deviceName, ':', '\0' };
Span<char> fullDeviceName = [deviceName, ':', '\0'];
char[]? rentedArray = null;

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static int GetUNCForNetworkDrive(char drive, out string? uncPath)
return ERROR_NOT_SUPPORTED;
}

ReadOnlySpan<char> driveName = stackalloc char[] { drive, ':', '\0' };
ReadOnlySpan<char> driveName = [drive, ':', '\0'];
int bufferSize = MAX_PATH;
Span<char> uncBuffer = stackalloc char[MAX_PATH];
if (InternalTestHooks.WNetGetConnectionBufferSize > 0 && InternalTestHooks.WNetGetConnectionBufferSize <= MAX_PATH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,15 +1902,16 @@ string ToModeString(FileSystemInfo fileSystemInfo)
}
}

bool isDirectory = fileAttributes.HasFlag(FileAttributes.Directory);
ReadOnlySpan<char> mode = stackalloc char[]
{
isLink ? 'l' : isDirectory ? 'd' : '-',
ReadOnlySpan<char> mode =
[
isLink ?
'l' :
fileAttributes.HasFlag(FileAttributes.Directory) ? 'd' : '-',
fileAttributes.HasFlag(FileAttributes.Archive) ? 'a' : '-',
fileAttributes.HasFlag(FileAttributes.ReadOnly) ? 'r' : '-',
fileAttributes.HasFlag(FileAttributes.Hidden) ? 'h' : '-',
fileAttributes.HasFlag(FileAttributes.System) ? 's' : '-',
};
];
return new string(mode);
}

Expand Down
14 changes: 4 additions & 10 deletions src/powershell/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ private static void AttemptExecPwshLogin(string[] args)
// At this point, we are on macOS

// Set up the mib array and the query for process maximum args size
Span<int> mib = stackalloc int[3];
int mibLength = 2;
mib[0] = MACOS_CTL_KERN;
mib[1] = MACOS_KERN_ARGMAX;
Span<int> mib = [MACOS_CTL_KERN, MACOS_KERN_ARGMAX];
int size = IntPtr.Size / 2;
int argmax = 0;

Expand All @@ -141,7 +138,7 @@ private static void AttemptExecPwshLogin(string[] args)
{
fixed (int *mibptr = mib)
{
ThrowOnFailure(nameof(argmax), SysCtl(mibptr, mibLength, &argmax, &size, IntPtr.Zero, 0));
ThrowOnFailure(nameof(argmax), SysCtl(mibptr, mib.Length, &argmax, &size, IntPtr.Zero, 0));
}
}

Expand All @@ -155,16 +152,13 @@ private static void AttemptExecPwshLogin(string[] args)
IntPtr executablePathPtr = IntPtr.Zero;
try
{
mib[0] = MACOS_CTL_KERN;
mib[1] = MACOS_KERN_PROCARGS2;
mib[2] = pid;
mibLength = 3;
mib = [MACOS_CTL_KERN, MACOS_KERN_PROCARGS2, pid];

unsafe
{
fixed (int *mibptr = mib)
{
ThrowOnFailure(nameof(procargs), SysCtl(mibptr, mibLength, procargs.ToPointer(), &argmax, IntPtr.Zero, 0));
ThrowOnFailure(nameof(procargs), SysCtl(mibptr, mib.Length, procargs.ToPointer(), &argmax, IntPtr.Zero, 0));
}

// The memory block we're reading is a series of null-terminated strings
Expand Down
Loading