Skip to content

Commit

Permalink
15x faster reflow in debug builds (#17550)
Browse files Browse the repository at this point in the history
STL iterators have a significant overhead. This improves performance
of `GetLastNonSpaceColumn` by >100x (it's too large to measure),
and reflow by ~15x in debug builds. This makes text reflow in debug
builds today ~10x faster than it used to be in release builds before
the large rewrites in #15701 and #13626.
  • Loading branch information
lhecker authored Jul 12, 2024
1 parent 7d77160 commit 04c33f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/buffer/out/Row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,15 @@ uint16_t ROW::size() const noexcept
til::CoordType ROW::GetLastNonSpaceColumn() const noexcept
{
const auto text = GetText();
const auto beg = text.begin();
const auto end = text.end();
const auto beg = text.data();
const auto end = beg + text.size();
#pragma warning(suppress : 26429) // Symbol 'it' is never tested for nullness, it can be marked as not_null (f.23).
auto it = end;

for (; it != beg; --it)
{
// it[-1] is safe as `it` is always greater than `beg` (loop invariant).
if (til::at(it, -1) != L' ')
if (it[-1] != L' ')
{
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/buffer/out/lib/bufferout.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<ItemGroup>
<ClInclude Include="..\cursor.h" />
<ClInclude Include="..\DbcsAttribute.hpp" />
<ClInclude Include="..\ICharRow.hpp" />
<ClInclude Include="..\ImageSlice.hpp" />
<ClInclude Include="..\LineRendition.hpp" />
<ClInclude Include="..\OutputCell.hpp" />
Expand All @@ -52,4 +51,4 @@
<!-- Careful reordering these. Some default props (contained in these files) are order sensitive. -->
<Import Project="$(SolutionDir)src\common.build.post.props" />
<Import Project="$(SolutionDir)src\common.nugetversions.targets" />
</Project>
</Project>

0 comments on commit 04c33f3

Please sign in to comment.