Skip to content

Commit

Permalink
only stackalloc the getwindowtitle buffer when length is small.
Browse files Browse the repository at this point in the history
  • Loading branch information
taooceros committed Dec 27, 2024
1 parent 02a4566 commit 9350e82
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ private static unsafe string GetWindowTitle(HWND hwnd)
{
var capacity = PInvoke.GetWindowTextLength(hwnd) + 1;
int length;
Span<char> buffer = stackalloc char[capacity];
Span<char> buffer = capacity < 1024 ? stackalloc char[capacity] : new char[capacity];
fixed (char* pBuffer = buffer)
{
// If the window has no title bar or text, if the title bar is empty,
// or if the window or control handle is invalid, the return value is zero.
length = PInvoke.GetWindowText(hwnd, (PWSTR)pBuffer, capacity);
length = PInvoke.GetWindowText(hwnd, pBuffer, capacity);
}

return buffer[..length].ToString();
Expand Down

0 comments on commit 9350e82

Please sign in to comment.