Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/DefaultTerminal.cpp (C++)

Code before:
#include <LibraryResources.h>

using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;

winrt::Windows::Foundation::Collections::IVector<Model::DefaultTerminal> DefaultTerminal::_available = winrt::single_threaded_vector<Model::DefaultTerminal>();
Model::DefaultTerminal DefaultTerminal::_current = nullptr;

DefaultTerminal::DefaultTerminal(DelegationConfig::DelegationPackage pkg) :
    _pkg(pkg)
{
}

winrt::hstring DefaultTerminal::Name() const
{
    static const std::wstring def{ RS_(L"InboxWindowsConsoleName") };
    return _pkg.terminal.name.empty() ? winrt::hstring{ def } : winrt::hstring{ _pkg.terminal.name };
}

winrt::hstring DefaultTerminal::Version() const
{
    // If there's no version information... return empty string instead.
    if (DelegationConfig::PkgVersion{} == _pkg.terminal.version)
    {
        return winrt::hstring{};
    }

    const auto name = fmt::format(L"{}.{}.{}.{}", _pkg.terminal.version.major, _pkg.terminal.version.minor, _pkg.terminal.version.build, _pkg.terminal.version.revision);
    return winrt::hstring{ name };
}

winrt::hstring DefaultTerminal::Author() const
{
    static const std::wstring def{ RS_(L"InboxWindowsConsoleAuthor") };
    return _pkg.terminal.author.empty() ? winrt::hstring{ def } : winrt::hstring{ _pkg.terminal.author };
}

winrt::hstring DefaultTerminal::Icon() const
{
    static const std::wstring_view def{ L"\uE756" };
    return _pkg.terminal.logo.empty() ? winrt::hstring{ def } : winrt::hstring{ _pkg.terminal.logo };
}

void DefaultTerminal::Refresh()
{
    std::vector<DelegationConfig::DelegationPackage> allPackages;
    DelegationConfig::DelegationPackage currentPackage;

    LOG_IF_FAILED(DelegationConfig::s_GetAvailablePackages(allPackages, currentPackage));

    _available.Clear();

Review comment (suggestion):
I feel like you should set a cleanup item to walk the entire solution to replace `fmt::format` with `fmt::format_to` as I bet we could be using the buffer and format_to way more often for better perf and memory usage.

Code after:
#include <LibraryResources.h>

using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;

DefaultTerminal::DefaultTerminal(DelegationConfig::DelegationPackage&& pkg) :
    _pkg{ pkg }
{
}

winrt::hstring DefaultTerminal::Name() const
{
    return _pkg.terminal.name.empty() ? winrt::hstring{ RS_(L"InboxWindowsConsoleName") } : winrt::hstring{ _pkg.terminal.name };
}

winrt::hstring DefaultTerminal::Version() const
{
    // If there's no version information... return empty string instead.
    const auto& version = _pkg.terminal.version;
    if (DelegationConfig::PkgVersion{} == version)
    {
        return winrt::hstring{};
    }

    fmt::wmemory_buffer buffer;
    fmt::format_to(buffer, L"{}.{}.{}.{}", version.major, version.minor, version.build, version.revision);
    return winrt::hstring{ buffer.data(), gsl::narrow_cast<winrt::hstring::size_type>(buffer.size()) };
}

winrt::hstring DefaultTerminal::Author() const
{
    return _pkg.terminal.author.empty() ? winrt::hstring{ RS_(L"InboxWindowsConsoleAuthor") } : winrt::hstring{ _pkg.terminal.author };
}

winrt::hstring DefaultTerminal::Icon() const
{
    return _pkg.terminal.logo.empty() ? winrt::hstring{ L"\uE756" } : winrt::hstring{ _pkg.terminal.logo };
}

std::pair<std::vector<Model::DefaultTerminal>, Model::DefaultTerminal> DefaultTerminal::Available()
{
    // The potential of returning nullptr for defaultTerminal feels weird, but XAML can
    // handle that appropriately and will select nothing as current in the dropdown.
    std::vector<Model::DefaultTerminal> defaultTerminals;
    Model::DefaultTerminal defaultTerminal{ nullptr };

    std::vector<DelegationConfig::DelegationPackage> allPackages;
    DelegationConfig::DelegationPackage currentPackage;
    LOG_IF_FAILED(DelegationConfig::s_GetAvailablePackages(allPackages, currentPackage));

    for (auto& pkg : allPackages)