Repository: microsoft/terminal
File: src/cascadia/TerminalControl/ControlCore.cpp (C++)

Code before:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "ControlCore.h"

// MidiAudio
#include <mmeapi.h>
#include <dsound.h>

#include <DefaultSettings.h>
#include <unicode.hpp>
#include <WinUser.h>
#include <LibraryResources.h>
#include <ranges>

#include "EventArgs.h"
#include "../../types/inc/GlyphWidth.hpp"
#include "../../buffer/out/search.h"
#include "../../renderer/atlas/AtlasEngine.h"
#include "../../renderer/dx/DxRenderer.hpp"

#include "ControlCore.g.cpp"
#include "SelectionColor.g.cpp"

using namespace ::Microsoft::Console::Types;
using namespace ::Microsoft::Console::VirtualTerminal;
using namespace ::Microsoft::Terminal::Core;
using namespace winrt::Windows::Graphics::Display;
using namespace winrt::Windows::System;
using namespace winrt::Windows::ApplicationModel::DataTransfer;

// The minimum delay between updates to the scroll bar's values.
// The updates are throttled to limit power usage.
constexpr const auto ScrollBarUpdateInterval = std::chrono::milliseconds(8);

// The minimum delay between updating the TSF input control.
constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);

// The minimum delay between updating the locations of regex patterns

Review comment (suggestion):
I'm not 100% sure if we should use `<ranges>` just yet. I've heard it can have a pretty significant compile duration impact and some testing indicates that this one use costs about 400ms on my machine (0.1%). Not that this matter to us, but to put this into perspective for some fun about generic languages in general, I can compile the entirety of SQLite in about a second (245k lines of C).

More importantly however, I'd personally prefer if ranges was used consistently throughout the entire project instead of this one use. It'd be a good, fun 1h Area-CodeHealth to replace all of our reverse-iterator uses and complex find()-loops with ranges all at once. This would also help figure out what the binary size impact will be (which I've heard is even more significant than the compile time impact).

Also, instead of `std::ranges::reverse_view{}` (which is the type) I believe one should use `std::views::reverse()` (the factory). Basically either of these are the usually expected usage:
```cpp
const auto& marks = _terminal->GetScrollMarks();
for (const auto& m : std::views::reverse(marks)) {}
for (const auto& m : marks | std::views::reverse) {}
```

Alternatively a regular reverse-iterator loops works as well of course:
```cpp
auto it = marks.rbegin();
const auto end = marks.rend();
for (; it != end; ++it)
{
    const auto& m = *it;
}
```

Code after:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "ControlCore.h"

// MidiAudio
#include <mmeapi.h>
#include <dsound.h>

#include <DefaultSettings.h>
#include <unicode.hpp>
#include <WinUser.h>
#include <LibraryResources.h>

#include "EventArgs.h"
#include "../../types/inc/GlyphWidth.hpp"
#include "../../buffer/out/search.h"
#include "../../renderer/atlas/AtlasEngine.h"
#include "../../renderer/dx/DxRenderer.hpp"

#include "ControlCore.g.cpp"
#include "SelectionColor.g.cpp"

using namespace ::Microsoft::Console::Types;
using namespace ::Microsoft::Console::VirtualTerminal;
using namespace ::Microsoft::Terminal::Core;
using namespace winrt::Windows::Graphics::Display;
using namespace winrt::Windows::System;
using namespace winrt::Windows::ApplicationModel::DataTransfer;

// The minimum delay between updates to the scroll bar's values.
// The updates are throttled to limit power usage.
constexpr const auto ScrollBarUpdateInterval = std::chrono::milliseconds(8);

// The minimum delay between updating the TSF input control.
constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);

// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);