Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
            {
                flags |= mod.flags;
            }
        }

        constexpr std::array<KeyModifier, 3> modalities{ {
            { VirtualKey::CapitalLock, ControlKeyStates::CapslockOn },
            { VirtualKey::NumberKeyLock, ControlKeyStates::NumlockOn },
            { VirtualKey::Scroll, ControlKeyStates::ScrolllockOn },
        } };

        for (const auto& mod : modalities)
        {
            const auto state = window.GetKeyState(mod.vkey);
            const auto isLocked = WI_IsFlagSet(state, CoreVirtualKeyStates::Locked);

            if (isLocked)
            {
                flags |= mod.flags;
            }
        }

        return flags;
    }

    til::point TermControl::_toControlOrigin(const til::point& terminalPos)
    {
        const til::size fontSize{ til::math::flooring, CharacterDimensions() };

        // Convert text buffer cursor position to client coordinate position
        // within the window. This point is in _pixels_
        const til::point clientCursorPos{ terminalPos * fontSize };

        // Get scale factor for view
        const double scaleFactor = SwapChainPanel().CompositionScaleX();

        const til::point clientCursorInDips{ til::math::flooring, clientCursorPos.x / scaleFactor, clientCursorPos.y / scaleFactor };

        auto padding{ GetPadding() };
        til::point relativeToOrigin{ til::math::flooring,
                                     clientCursorInDips.x + padding.Left,
                                     clientCursorInDips.y + padding.Top };
        return relativeToOrigin;
    }

    // Method Description:
    // - Gets the corresponding viewport pixel position for the cursor
    //    by excluding the padding.
    // Arguments:
    // - cursorPosition: the (x,y) position of a given cursor (i.e.: mouse cursor).
    //    NOTE: origin (0,0) is top-left.

Review comment (suggestion):
You can pass `point`s by value - they're small! At just 8 bytes, they'll be passed as a register argument.

Code after:
        } };

        ControlKeyStates flags;

        for (const auto& mod : modifiers)
        {
            const auto state = window.GetKeyState(mod.vkey);
            const auto isDown = WI_IsFlagSet(state, CoreVirtualKeyStates::Down);

            if (isDown)
            {
                flags |= mod.flags;
            }
        }

        constexpr std::array<KeyModifier, 3> modalities{ {
            { VirtualKey::CapitalLock, ControlKeyStates::CapslockOn },
            { VirtualKey::NumberKeyLock, ControlKeyStates::NumlockOn },
            { VirtualKey::Scroll, ControlKeyStates::ScrolllockOn },
        } };

        for (const auto& mod : modalities)
        {
            const auto state = window.GetKeyState(mod.vkey);
            const auto isLocked = WI_IsFlagSet(state, CoreVirtualKeyStates::Locked);

            if (isLocked)
            {
                flags |= mod.flags;
            }
        }

        return flags;
    }

    til::point TermControl::_toControlOrigin(const til::point terminalPos)
    {
        const auto fontSize{ CharacterDimensions() };

        // Convert text buffer cursor position to client coordinate position
        // within the window. This point is in _pixels_
        const double clientCursorPosX = terminalPos.x * fontSize.Width;
        const double clientCursorPosY = terminalPos.y * fontSize.Height;

        // Get scale factor for view
        const double scaleFactor = SwapChainPanel().CompositionScaleX();

        const double clientCursorInDipsX = clientCursorPosX / scaleFactor;
        const double clientCursorInDipsY = clientCursorPosY / scaleFactor;

        auto padding{ GetPadding() };