Remove unneeded c_str() conversions (#4358)

* Remove unneeded c_str() calls when converting an hstring to a wstring_view.

* Remove unneeded c_str() calls when constructing a FontInfo class with a wstring face name.

* Remove unneeded winrt::to_hstring calls when passing a wstring to a method that expects an hstring.

* Remove unneeded c_str() calls when passing an hstring to a method that already accepts hstrings without conversion.

* Remove unneeded c_str() and data() calls when explicitly constructing an hstring from a wstring.
This commit is contained in:
James Holderness 2020-01-27 18:23:13 +00:00 committed by Carlos Zamora
parent 830c22b73e
commit 8c46e740e8
7 changed files with 17 additions and 17 deletions

View file

@ -46,8 +46,8 @@ static bool RegisterTermClass(HINSTANCE hInstance) noexcept
}
HwndTerminal::HwndTerminal(HWND parentHwnd) :
_desiredFont{ DEFAULT_FONT_FACE.c_str(), 0, 10, { 0, 14 }, CP_UTF8 },
_actualFont{ DEFAULT_FONT_FACE.c_str(), 0, 10, { 0, 14 }, CP_UTF8, false }
_desiredFont{ DEFAULT_FONT_FACE, 0, 10, { 0, 14 }, CP_UTF8 },
_actualFont{ DEFAULT_FONT_FACE, 0, 10, { 0, 14 }, CP_UTF8, false }
{
HINSTANCE hInstance = wil::GetModuleInstanceHandle();

View file

@ -185,12 +185,12 @@ TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map<std::w
terminalSettings.FontSize(_fontSize);
terminalSettings.Padding(_padding);
terminalSettings.Commandline(winrt::to_hstring(_commandline.c_str()));
terminalSettings.Commandline(_commandline);
if (_startingDirectory)
{
const auto evaluatedDirectory = Profile::EvaluateStartingDirectory(_startingDirectory.value());
terminalSettings.StartingDirectory(winrt::to_hstring(evaluatedDirectory.c_str()));
terminalSettings.StartingDirectory(evaluatedDirectory);
}
// GH#2373: Use the tabTitle as the starting title if it exists, otherwise
@ -231,7 +231,7 @@ TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map<std::w
if (HasBackgroundImage())
{
terminalSettings.BackgroundImage(GetExpandedBackgroundImagePath().c_str());
terminalSettings.BackgroundImage(GetExpandedBackgroundImagePath());
}
if (_backgroundImageOpacity)

View file

@ -267,7 +267,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
const auto textRequested = _inputBuffer.substr(range.StartCaretPosition, static_cast<size_t>(range.EndCaretPosition) - static_cast<size_t>(range.StartCaretPosition));
args.Request().Text(winrt::to_hstring(textRequested.c_str()));
args.Request().Text(textRequested);
}
CATCH_LOG();
}
@ -318,7 +318,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_inputBuffer = _inputBuffer.replace(
range.StartCaretPosition,
static_cast<size_t>(range.EndCaretPosition) - static_cast<size_t>(range.StartCaretPosition),
text.c_str());
text);
_textBlock.Text(_inputBuffer);

View file

@ -60,8 +60,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_autoScrollingPointerPoint{ std::nullopt },
_autoScrollTimer{},
_lastAutoScrollUpdateTime{ std::nullopt },
_desiredFont{ DEFAULT_FONT_FACE.c_str(), 0, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8 },
_actualFont{ DEFAULT_FONT_FACE.c_str(), 0, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false },
_desiredFont{ DEFAULT_FONT_FACE, 0, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8 },
_actualFont{ DEFAULT_FONT_FACE, 0, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false },
_touchAnchor{ std::nullopt },
_cursorTimer{},
_lastMouseClick{},
@ -336,7 +336,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
}
// Initialize our font information.
const auto* fontFace = _settings.FontFace().c_str();
const auto fontFace = _settings.FontFace();
const short fontHeight = gsl::narrow<short>(_settings.FontSize());
// The font width doesn't terribly matter, we'll only be using the
// height to look it up
@ -649,7 +649,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// This event is explicitly revoked in the destructor: does not need weak_ref
auto onRecieveOutputFn = [this](const hstring str) {
_terminal->Write(str.c_str());
_terminal->Write(str);
};
_connectionOutputEventToken = _connection.TerminalOutput(onRecieveOutputFn);
@ -1458,7 +1458,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
// Make sure we have a non-zero font size
const auto newSize = std::max(gsl::narrow<short>(fontSize), static_cast<short>(1));
const auto* fontFace = _settings.FontFace().c_str();
const auto fontFace = _settings.FontFace();
_actualFont = { fontFace, 0, 10, { 0, newSize }, CP_UTF8, false };
_desiredFont = { _actualFont };
@ -1707,7 +1707,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
}
// send data up for clipboard
auto copyArgs = winrt::make_self<CopyToClipboardEventArgs>(winrt::hstring(textData.data(), gsl::narrow<winrt::hstring::size_type>(textData.size())),
auto copyArgs = winrt::make_self<CopyToClipboardEventArgs>(winrt::hstring(textData),
winrt::to_hstring(htmlData),
winrt::to_hstring(rtfData));
_clipboardCopyHandlers(*this, *copyArgs);
@ -1811,7 +1811,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
winrt::Windows::Foundation::Point TermControl::GetProposedDimensions(IControlSettings const& settings, const uint32_t dpi)
{
// Initialize our font information.
const auto* fontFace = settings.FontFace().c_str();
const auto fontFace = settings.FontFace();
const short fontHeight = gsl::narrow<short>(settings.FontSize());
// The font width doesn't terribly matter, we'll only be using the
// height to look it up

View file

@ -40,7 +40,7 @@ const FontInfo& Terminal::GetFontInfo() noexcept
// by this method.
// We could very likely replace this with just an IsRasterFont method
// (which would return false)
static const FontInfo _fakeFontInfo(DEFAULT_FONT_FACE.c_str(), TMPF_TRUETYPE, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false);
static const FontInfo _fakeFontInfo(DEFAULT_FONT_FACE, TMPF_TRUETYPE, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false);
return _fakeFontInfo;
}
#pragma warning(pop)

View file

@ -32,7 +32,7 @@ namespace TerminalCoreUnitTests
uint32_t CursorColor() { return COLOR_WHITE; }
CursorStyle CursorShape() const noexcept { return CursorStyle::Vintage; }
uint32_t CursorHeight() { return 42UL; }
winrt::hstring WordDelimiters() { return winrt::to_hstring(DEFAULT_WORD_DELIMITERS.c_str()); }
winrt::hstring WordDelimiters() { return winrt::hstring(DEFAULT_WORD_DELIMITERS); }
bool CopyOnSelect() { return _copyOnSelect; }
winrt::hstring StartingTitle() { return _startingTitle; }
bool SuppressApplicationTitle() { return _suppressApplicationTitle; }

View file

@ -169,7 +169,7 @@ void AppHost::Initialize()
// - <none>
void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /*sender*/, winrt::hstring newTitle)
{
_window->UpdateTitle(newTitle.c_str());
_window->UpdateTitle(newTitle);
}
// Method Description: