Skip to content

Commit

Permalink
Enable WINRT_LEAN_AND_MEAN (#15215)
Browse files Browse the repository at this point in the history
`WINRT_LEAN_AND_MEAN` removes a bunch of less often used parts of the
C++/WinRT headers:

- `std::hash` specializations for every object
- `operator <<(ostream)` overloads for any `IStringable`
- Interface producers for interfaces that are marked "exclusive"

There's only one place where we were using even one of these.

Enabling this saves us (optimistically) 30 seconds of build time on the
CI agents and shrinks our largest PCH (TerminalApp, x64, Debug) by about
150MiB.

It's not huge, but it's not nothing.
  • Loading branch information
DHowett authored Apr 24, 2023
1 parent ee05307 commit 2cfd73d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "CommandPalette.g.h"
#include "AppCommandlineArgs.h"

#include <til/hash.h>

// fwdecl unittest classes
namespace TerminalAppLocalTests
{
Expand Down Expand Up @@ -60,6 +62,14 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(PreviewAction, Windows::Foundation::IInspectable, Microsoft::Terminal::Settings::Model::Command);

private:
struct winrt_object_hash
{
size_t operator()(const auto& value) const noexcept
{
return til::hash(winrt::get_abi(value));
}
};

friend struct CommandPaletteT<CommandPalette>; // for Xaml to bind events

Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _allCommands{ nullptr };
Expand Down Expand Up @@ -141,7 +151,7 @@ namespace winrt::TerminalApp::implementation
void _choosingItemContainer(const Windows::UI::Xaml::Controls::ListViewBase& sender, const Windows::UI::Xaml::Controls::ChoosingItemContainerEventArgs& args);
void _containerContentChanging(const Windows::UI::Xaml::Controls::ListViewBase& sender, const Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs& args);
winrt::TerminalApp::PaletteItemTemplateSelector _itemTemplateSelector{ nullptr };
std::unordered_map<Windows::UI::Xaml::DataTemplate, std::unordered_set<Windows::UI::Xaml::Controls::Primitives::SelectorItem>> _listViewItemsCache;
std::unordered_map<Windows::UI::Xaml::DataTemplate, std::unordered_set<Windows::UI::Xaml::Controls::Primitives::SelectorItem, winrt_object_hash>, winrt_object_hash> _listViewItemsCache;
Windows::UI::Xaml::DataTemplate _listItemTemplate;

friend class TerminalAppLocalTests::TabTests;
Expand Down
2 changes: 2 additions & 0 deletions src/cppwinrt.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<DisableSpecificWarnings>5104;28204;%(DisableSpecificWarnings)</DisableSpecificWarnings>

<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>

<PreprocessorDefinitions>WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem Condition="'%(SubSystem)'==''">Console</SubSystem>
Expand Down

0 comments on commit 2cfd73d

Please sign in to comment.