Skip to content

Commit

Permalink
Replace std::map with std::unordered_map (#6640)
Browse files Browse the repository at this point in the history
Replace std::map with std::unordered_map when the order doesn't matter
and hash functions are provided. Simple optimizations, but I expect the
performance should be strictly better, especially for
CodepointWidthDetector.hpp.
  • Loading branch information
ZhaoMJ authored Jun 23, 2020
1 parent ff23be0 commit b24dbf7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/buffer/out/UnicodeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void UnicodeStorage::Erase(const key_type key)
// - rowMap - A map of the old row IDs to the new row IDs.
// - width - The width of the new row. Remove any items that are beyond the row width.
// - Use nullopt if we're not resizing the width of the row, just renumbering the rows.
void UnicodeStorage::Remap(const std::map<SHORT, SHORT>& rowMap, const std::optional<SHORT> width)
void UnicodeStorage::Remap(const std::unordered_map<SHORT, SHORT>& rowMap, const std::optional<SHORT> width)
{
// Make a temporary map to hold all the new row positioning
std::unordered_map<key_type, mapped_type> newMap;
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/out/UnicodeStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UnicodeStorage final

void Erase(const key_type key);

void Remap(const std::map<SHORT, SHORT>& rowMap, const std::optional<SHORT> width);
void Remap(const std::unordered_map<SHORT, SHORT>& rowMap, const std::optional<SHORT> width);

private:
std::unordered_map<key_type, mapped_type> _map;
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ UnicodeStorage& TextBuffer::GetUnicodeStorage() noexcept
// - newRowWidth - Optional new value for the row width.
void TextBuffer::_RefreshRowIDs(std::optional<SHORT> newRowWidth)
{
std::map<SHORT, SHORT> rowMap;
std::unordered_map<SHORT, SHORT> rowMap;
SHORT i = 0;
for (auto& it : _storage)
{
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/WpfTerminalControl/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum WindowMessage : int
/// </summary>
WM_MOUSEACTIVATE = 0x0021,

/// <summary>
/// The WM_GETOBJECT message is sent by Active Accessibility when a client calls AccessibleObjectFromWindow or any of the other AccessibleObjectFromX APIs that retrieve an interface to an object.
/// </summary>
WM_GETOBJECT = 0x003D,

/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/WpfTerminalControl/TerminalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public TerminalContainer()
/// </summary>
internal int Columns { get; private set; }

/// <summary>
/// Gets the window handle of the terminal.
/// </summary>
internal IntPtr Hwnd => this.hwnd;

/// <summary>
Expand Down Expand Up @@ -238,7 +241,7 @@ private IntPtr TerminalContainer_MessageHook(IntPtr hwnd, int msg, IntPtr wParam
NativeMethods.TerminalSetCursorVisible(this.terminal, true);
ulong scanCode = (((ulong)lParam) & 0x00FF0000) >> 16;

NativeMethods.TerminalSendKeyEvent(this.terminal, (ushort)wParam, (ushort)(scanCode), true);
NativeMethods.TerminalSendKeyEvent(this.terminal, (ushort)wParam, (ushort)scanCode, true);
this.blinkTimer?.Start();
break;
}
Expand All @@ -247,7 +250,7 @@ private IntPtr TerminalContainer_MessageHook(IntPtr hwnd, int msg, IntPtr wParam
{
// WM_KEYUP lParam layout documentation: https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keyup
ulong scanCode = (((ulong)lParam) & 0x00FF0000) >> 16;
NativeMethods.TerminalSendKeyEvent(this.terminal, (ushort)wParam, (ushort)(scanCode), false);
NativeMethods.TerminalSendKeyEvent(this.terminal, (ushort)wParam, (ushort)scanCode, false);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/interactivity/win32/windowUiaProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Microsoft::Console::Interactivity::Win32
// eventually overflowing the stack.
// We aren't using this as a cheap locking
// mechanism for multi-threaded code.
std::map<EVENTID, bool> _signalEventFiring;
std::unordered_map<EVENTID, bool> _signalEventFiring;

[[nodiscard]] HRESULT _EnsureValidHwnd() const;

Expand Down
2 changes: 1 addition & 1 deletion src/types/ScreenInfoUiaProviderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Microsoft::Console::Types
// eventually overflowing the stack.
// We aren't using this as a cheap locking
// mechanism for multi-threaded code.
std::map<EVENTID, bool> _signalFiringMapping{};
std::unordered_map<EVENTID, bool> _signalFiringMapping{};

const COORD _getScreenBufferCoords() const;
const TextBuffer& _getTextBuffer() const noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/types/inc/CodepointWidthDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class CodepointWidthDetector final
bool _checkFallbackViaCache(const std::wstring_view glyph) const;
static unsigned int _extractCodepoint(const std::wstring_view glyph) noexcept;

mutable std::map<std::wstring, bool> _fallbackCache;
mutable std::unordered_map<std::wstring, bool> _fallbackCache;
std::function<bool(std::wstring_view)> _pfnFallbackMethod;
};

0 comments on commit b24dbf7

Please sign in to comment.