Skip to content

Commit

Permalink
use switch-case instead
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jun 7, 2021
1 parent 386297a commit 285bc45
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
using namespace winrt::Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal::Control;

#define CHECK_IF_ACTION_WITH_ARG(myAction, actionWithArg, result) \
if (myAction == ShortcutAction::actionWithArg) \
{ \
result = winrt::make<actionWithArg##Args>(); \
}

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
static InternalActionID Hash(const Model::ActionAndArgs& actionAndArgs)
Expand All @@ -25,24 +19,30 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
size_t hashedArgs{};
if (const auto& args{ actionAndArgs.Args() })
{
// Args are defined, so hash them
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)
// Args are not defined.
// Check if the ShortcutAction supports args.
switch (actionAndArgs.Action())
{
hashedArgs = gsl::narrow_cast<size_t>(hiddenActionArgs.Hash());
}
else
#define ON_ALL_ACTIONS_WITH_ARGS(action) \
case ShortcutAction::action: \
{ \
/* If it does, hash the default values for the args.*/ \
hashedArgs = gsl::narrow_cast<size_t>(make<action##Args>().Hash()); \
break; \
}
ALL_SHORTCUT_ACTIONS_WITH_ARGS
#undef ON_ALL_ACTIONS_WITH_ARGS
default:
{
// Otherwise, hash nullptr.
std::hash<IActionArgs> argsHash;
hashedArgs = argsHash(hiddenActionArgs);
hashedArgs = argsHash(nullptr);
}
}
}
return hashedAction ^ hashedArgs;
Expand Down

0 comments on commit 285bc45

Please sign in to comment.