Skip to content

Commit

Permalink
Remove unneeded c_str() conversions (#4358)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
j4james authored and carlos-zamora committed Jan 27, 2020
1 parent 830c22b commit 8c46e74
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/cascadia/PublicTerminalCore/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/TSFInputControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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
Expand Down Expand 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);

Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/UnitTests_TerminalCore/MockTermSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8c46e74

Please sign in to comment.