Increase VtInputThread buffer size (#16470)

This makes 3 improvements:
* 16x larger input buffer size improves behavior when pasting
  clipboard contents while the win32-input-mode is enabled,
  as each input character is roughly 15-20x longer after encoding.
* Translate UTF8 to UTF16 outside of the console lock.
* Preserve the UTF16 buffer between reads for less mallocs.
This commit is contained in:
Leonard Hecker 2023-12-15 20:17:42 +01:00 committed by GitHub
parent f5b45c25c9
commit 171a21ad48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -69,7 +69,7 @@ DWORD WINAPI VtInputThread::StaticVtInputThreadProc(_In_ LPVOID lpParameter)
// - true if you should continue reading // - true if you should continue reading
bool VtInputThread::DoReadInput() bool VtInputThread::DoReadInput()
{ {
char buffer[256]; char buffer[4096];
DWORD dwRead = 0; DWORD dwRead = 0;
const auto ok = ReadFile(_hFile.get(), buffer, ARRAYSIZE(buffer), &dwRead, nullptr); const auto ok = ReadFile(_hFile.get(), buffer, ARRAYSIZE(buffer), &dwRead, nullptr);
@ -89,6 +89,12 @@ bool VtInputThread::DoReadInput()
return false; return false;
} }
// If we hit a parsing error, eat it. It's bad utf-8, we can't do anything with it.
if (FAILED_LOG(til::u8u16({ buffer, gsl::narrow_cast<size_t>(dwRead) }, _wstr, _u8State)))
{
return true;
}
try try
{ {
// Make sure to call the GLOBAL Lock/Unlock, not the gci's lock/unlock. // Make sure to call the GLOBAL Lock/Unlock, not the gci's lock/unlock.
@ -99,12 +105,7 @@ bool VtInputThread::DoReadInput()
LockConsole(); LockConsole();
const auto unlock = wil::scope_exit([&] { UnlockConsole(); }); const auto unlock = wil::scope_exit([&] { UnlockConsole(); });
std::wstring wstr; _pInputStateMachine->ProcessString(_wstr);
// If we hit a parsing error, eat it. It's bad utf-8, we can't do anything with it.
if (SUCCEEDED_LOG(til::u8u16({ buffer, gsl::narrow_cast<size_t>(dwRead) }, wstr, _u8State)))
{
_pInputStateMachine->ProcessString(wstr);
}
} }
CATCH_LOG(); CATCH_LOG();

View File

@ -39,5 +39,6 @@ namespace Microsoft::Console
std::unique_ptr<Microsoft::Console::VirtualTerminal::StateMachine> _pInputStateMachine; std::unique_ptr<Microsoft::Console::VirtualTerminal::StateMachine> _pInputStateMachine;
til::u8state _u8State; til::u8state _u8State;
std::wstring _wstr;
}; };
} }