Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/ColorScheme.h (C/C++)

Code before:
{
    class SettingsTests;
    class ColorSchemeTests;
};

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
    struct ColorScheme : ColorSchemeT<ColorScheme>
    {
    public:
        ColorScheme();
        ColorScheme(hstring name, Windows::UI::Color defaultFg, Windows::UI::Color defaultBg, Windows::UI::Color cursorColor);
        com_ptr<ColorScheme> Copy() const;

        static com_ptr<ColorScheme> FromJson(const Json::Value& json);
        bool ShouldBeLayered(const Json::Value& json) const;
        void LayerJson(const Json::Value& json);

        Json::Value ToJson() const;

        static std::optional<std::wstring> GetNameFromJson(const Json::Value& json);

        com_array<Windows::UI::Color> Table() const noexcept;
        void SetColorTableEntry(uint8_t index, const winrt::Windows::UI::Color& value) noexcept;

        static bool ValidateColorScheme(const Json::Value scheme);

        GETSET_PROPERTY(winrt::hstring, Name);
        GETSET_COLORPROPERTY(Foreground); // defined in constructor
        GETSET_COLORPROPERTY(Background); // defined in constructor
        GETSET_COLORPROPERTY(SelectionBackground); // defined in constructor
        GETSET_COLORPROPERTY(CursorColor); // defined in constructor

    private:
        std::array<til::color, COLOR_TABLE_SIZE> _table;

        friend class SettingsModelLocalTests::SettingsTests;
        friend class SettingsModelLocalTests::ColorSchemeTests;
    };
}


Review comment (performance):
gotta make this a `const JsonValue&` -- otherwise we are making an expensive copy of a whole json object tree every time we call this!

Code after:
{
    class SettingsTests;
    class ColorSchemeTests;
};

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
    struct ColorScheme : ColorSchemeT<ColorScheme>
    {
    public:
        ColorScheme();
        ColorScheme(hstring name);
        ColorScheme(hstring name, COLORREF defaultFg, COLORREF defaultBg, COLORREF cursorColor);
        com_ptr<ColorScheme> Copy() const;

        static com_ptr<ColorScheme> FromJson(const Json::Value& json);
        bool ShouldBeLayered(const Json::Value& json) const;
        void LayerJson(const Json::Value& json);

        Json::Value ToJson() const;

        static std::optional<std::wstring> GetNameFromJson(const Json::Value& json);

        com_array<Windows::UI::Color> Table() const noexcept;
        void SetColorTableEntry(uint8_t index, const winrt::Windows::UI::Color& value) noexcept;

        static bool ValidateColorScheme(const Json::Value& scheme);

        GETSET_PROPERTY(winrt::hstring, Name);
        GETSET_COLORPROPERTY(Foreground); // defined in constructor
        GETSET_COLORPROPERTY(Background); // defined in constructor
        GETSET_COLORPROPERTY(SelectionBackground); // defined in constructor
        GETSET_COLORPROPERTY(CursorColor); // defined in constructor

    private:
        std::array<til::color, COLOR_TABLE_SIZE> _table;

        friend class SettingsModelLocalTests::SettingsTests;
        friend class SettingsModelLocalTests::ColorSchemeTests;
    };
}

namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
{
    BASIC_FACTORY(ColorScheme);
}