Skip to content

Commit

Permalink
cache the special hash value
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jun 10, 2021
1 parent 96a08ba commit d83a764
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ constexpr size_t Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(c
return gsl::narrow_cast<size_t>(args.Hash());
}

// Retrieves the hash value for an empty-constructed object.
template<typename T>
static size_t EmptyHash()
{
// cache the value of the empty hash
static size_t cachedHash{ 0 };
if (!cachedHash)
{
cachedHash = { winrt::make_self<T>()->Hash() };
}
return cachedHash;
}

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
using namespace ::Microsoft::Terminal::Settings::Model;
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// 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 = gsl::narrow_cast<size_t>(make<action##Args>().Hash()); \
#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
Expand Down

0 comments on commit d83a764

Please sign in to comment.