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

Code before:
{
    static InternalActionID Hash(const Model::ActionAndArgs& actionAndArgs)
    {
        size_t hashedAction{ HashUtils::HashProperty(actionAndArgs.Action()) };

        size_t hashedArgs{};
        if (const auto& args{ actionAndArgs.Args() })
        {
            hashedArgs = gsl::narrow_cast<size_t>(args.Hash());
        }
        else
        {
            // Check if this action is supposed to have args.
            Model::IActionArgs hiddenActionArgs{ nullptr };
#define ON_ALL_ACTIONS_WITH_ARGS(action) CHECK_IF_ACTION_WITH_ARG(actionAndArgs.Action(), action, hiddenActionArgs)
            ALL_SHORTCUT_ACTIONS_WITH_ARGS
#undef ON_ALL_ACTIONS_WITH_ARGS

            if (hiddenActionArgs)
            {
                hashedArgs = gsl::narrow_cast<size_t>(hiddenActionArgs.Hash());
            }
            else
            {
                std::hash<IActionArgs> argsHash;
                hashedArgs = argsHash(hiddenActionArgs);
            }
        }
        return hashedAction ^ hashedArgs;
    }

    ActionMap::ActionMap() :
        _NestedCommands{ single_threaded_map<hstring, Model::Command>() }
    {
    }

    // Method Description:
    // - Retrieves the Command in the current layer, if it's valid
    // - We internally store invalid commands as full commands.
    //    This helper function returns nullptr when we get an invalid
    //    command. This allows us to simply check for null when we
    //    want a valid command.
    // Arguments:
    // - actionID: the internal ID associated with a Command
    // Return Value:
    // - If the command is valid, the command itself.
    // - If the command is explicitly unbound, nullptr.
    // - If the command cannot be found in this layer, nullopt.
    std::optional<Model::Command> ActionMap::_GetActionByID(const InternalActionID actionID) const
    {
        // Check the masking actions

Review comment (bug):
Oh btw: `hiddenActionArgs` is always a `nullptr` here.

Code after:
        if (const auto& args{ actionAndArgs.Args() })
        {
            // Args are defined, so hash them
            hashedArgs = gsl::narrow_cast<size_t>(args.Hash());
        }
        else
        {
            // Args are not defined.
            // Check if the ShortcutAction supports args.
            switch (actionAndArgs.Action())
            {
#define ON_ALL_ACTIONS_WITH_ARGS(action)                        \
    case ShortcutAction::action:                                \
        /* If it does, hash the default values for the args.*/  \
        hashedArgs = EmptyHash<implementation::action##Args>(); \
        break;
                ALL_SHORTCUT_ACTIONS_WITH_ARGS
#undef ON_ALL_ACTIONS_WITH_ARGS
            default:
            {
                // Otherwise, hash nullptr.
                std::hash<IActionArgs> argsHash;
                hashedArgs = argsHash(nullptr);
            }
            }
        }
        return hashedAction ^ hashedArgs;
    }

    ActionMap::ActionMap() :
        _NestedCommands{ single_threaded_map<hstring, Model::Command>() },
        _IterableCommands{ single_threaded_vector<Model::Command>() }
    {
    }

    // Method Description:
    // - Retrieves the Command in the current layer, if it's valid
    // - We internally store invalid commands as full commands.
    //    This helper function returns nullptr when we get an invalid
    //    command. This allows us to simply check for null when we
    //    want a valid command.
    // Arguments:
    // - actionID: the internal ID associated with a Command
    // Return Value:
    // - If the command is valid, the command itself.
    // - If the command is explicitly unbound, nullptr.
    // - If the command cannot be found in this layer, nullopt.
    std::optional<Model::Command> ActionMap::_GetActionByID(const InternalActionID actionID) const
    {
        // Check the masking actions
        const auto maskingPair{ _MaskingActions.find(actionID) };