From d83a764899d308f3028756081581d942d9badfce Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 10 Jun 2021 13:37:44 -0700 Subject: [PATCH] cache the special hash value --- src/cascadia/TerminalSettingsModel/ActionArgs.h | 13 +++++++++++++ src/cascadia/TerminalSettingsModel/ActionMap.cpp | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.h b/src/cascadia/TerminalSettingsModel/ActionArgs.h index 6cf7d8cb53a..40d178b7df1 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.h @@ -68,6 +68,19 @@ constexpr size_t Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(c return gsl::narrow_cast(args.Hash()); } +// Retrieves the hash value for an empty-constructed object. +template +static size_t EmptyHash() +{ + // cache the value of the empty hash + static size_t cachedHash{ 0 }; + if (!cachedHash) + { + cachedHash = { winrt::make_self()->Hash() }; + } + return cachedHash; +} + namespace winrt::Microsoft::Terminal::Settings::Model::implementation { using namespace ::Microsoft::Terminal::Settings::Model; diff --git a/src/cascadia/TerminalSettingsModel/ActionMap.cpp b/src/cascadia/TerminalSettingsModel/ActionMap.cpp index 15dcf46e1ae..5decbab3d76 100644 --- a/src/cascadia/TerminalSettingsModel/ActionMap.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionMap.cpp @@ -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(make().Hash()); \ +#define ON_ALL_ACTIONS_WITH_ARGS(action) \ + case ShortcutAction::action: \ + /* If it does, hash the default values for the args.*/ \ + hashedArgs = EmptyHash(); \ break; ALL_SHORTCUT_ACTIONS_WITH_ARGS #undef ON_ALL_ACTIONS_WITH_ARGS