Repository: microsoft/terminal
File: src/host/getset.cpp (C++)

Code before:
        }
        const COORD newBufferSize = context.GetBufferSize().Dimensions();

        for (size_t i = 0; i < std::size(data.ColorTable); i++)
        {
            gci.SetLegacyColorTableEntry(i, data.ColorTable[i]);
        }

        // GH#399: Trigger a redraw, so that updated colors are repainted, but
        // only do this if we're not in conpty mode. ConPTY will update the
        // colors of the palette elsewhere (after TODO GH#10639)
        if (!gci.IsInVtIoMode())
        {
            auto* pRender = ServiceLocator::LocateGlobals().pRender;
            if (pRender)
            {
                pRender->TriggerRedrawAll();
            }
        }

        context.SetDefaultAttributes(TextAttribute{ data.wAttributes }, TextAttribute{ data.wPopupAttributes });

        const Viewport requestedViewport = Viewport::FromExclusive(data.srWindow);

        COORD NewSize = requestedViewport.Dimensions();
        // If we have a window, clamp the requested viewport to the max window size
        if (!ServiceLocator::LocateGlobals().IsHeadless())
        {
            NewSize.X = std::min(NewSize.X, data.dwMaximumWindowSize.X);
            NewSize.Y = std::min(NewSize.Y, data.dwMaximumWindowSize.Y);
        }

        // If wrap text is on, then the window width must be the same size as the buffer width
        if (gci.GetWrapText())
        {
            NewSize.X = newBufferSize.X;
        }

        if (NewSize.X != context.GetViewport().Width() ||
            NewSize.Y != context.GetViewport().Height())
        {
            // GH#1856 - make sure to hide the commandline _before_ we execute
            // the resize, and the re-display it after the resize. If we leave
            // it displayed, we'll crash during the resize when we try to figure
            // out if the bounds of the old commandline fit within the new
            // window (it might not).
            CommandLine& commandLine = CommandLine::Instance();
            commandLine.Hide(FALSE);
            context.SetViewportSize(&NewSize);
            commandLine.Show();


Review comment (performance):
this shouldn't introduce a poor performance case for applications that aren't intending on changing the colors, right?

Code after:
        }
        const auto newBufferSize = context.GetBufferSize().Dimensions();

        bool changedOneTableEntry = false;
        for (size_t i = 0; i < std::size(data.ColorTable); i++)
        {
            // Check if we actually changed a palette color
            const auto& newColor{ data.ColorTable[i] };
            changedOneTableEntry = changedOneTableEntry || (newColor != gci.GetColorTableEntry(i));

            // Set the new value.
            gci.SetLegacyColorTableEntry(i, newColor);
        }

        // GH#399: Trigger a redraw, so that updated colors are repainted, but
        // only do this if we're not in conpty mode. ConPTY will update the
        // colors of the palette elsewhere (after TODO GH#10639)
        //
        // Only do this if we actually changed the value of the palette though -
        // this API gets called all the time to change all sorts of things, but
        // not necessarily the palette.
        if (changedOneTableEntry && !gci.IsInVtIoMode())
        {
            if (auto* pRender{ ServiceLocator::LocateGlobals().pRender })
            {
                pRender->TriggerRedrawAll();
            }
        }

        context.SetDefaultAttributes(TextAttribute{ data.wAttributes }, TextAttribute{ data.wPopupAttributes });

        const auto requestedViewport = Viewport::FromExclusive(data.srWindow);

        auto NewSize = requestedViewport.Dimensions();
        // If we have a window, clamp the requested viewport to the max window size
        if (!ServiceLocator::LocateGlobals().IsHeadless())
        {
            NewSize.X = std::min(NewSize.X, data.dwMaximumWindowSize.X);
            NewSize.Y = std::min(NewSize.Y, data.dwMaximumWindowSize.Y);
        }

        // If wrap text is on, then the window width must be the same size as the buffer width
        if (gci.GetWrapText())
        {
            NewSize.X = newBufferSize.X;
        }

        if (NewSize.X != context.GetViewport().Width() ||
            NewSize.Y != context.GetViewport().Height())
        {
            // GH#1856 - make sure to hide the commandline _before_ we execute