Skip to content

Commit bb47e9e

Browse files
committed
Less diff, again
1 parent af63923 commit bb47e9e

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

src/buffer/out/Row.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -641,34 +641,34 @@ catch (...)
641641
//
642642
// We can infer the "end" from the amount of columns we're given (colLimit - colBeg),
643643
// because ASCII is always 1 column wide per character.
644-
auto len = std::min<size_t>(chars.size(), colLimit - colEnd);
644+
auto it = chars.begin();
645+
const auto end = it + std::min<size_t>(chars.size(), colLimit - colBeg);
645646
size_t ch = chBeg;
646-
size_t off = 0;
647647

648-
for (; off < len; ++off)
648+
while (it != end)
649649
{
650-
if (chars[off] >= 0x80) [[unlikely]]
650+
if (*it >= 0x80) [[unlikely]]
651651
{
652-
_replaceTextUnicode(ch, off);
652+
_replaceTextUnicode(ch, it);
653653
return;
654654
}
655655

656656
til::at(row._charOffsets, colEnd) = gsl::narrow_cast<uint16_t>(ch);
657657
++colEnd;
658658
++ch;
659+
++it;
659660
}
660661

661662
colEndDirty = colEnd;
662663
charsConsumed = ch - chBeg;
663664
}
664665

665-
[[msvc::forceinline]] void ROW::WriteHelper::_replaceTextUnicode(size_t ch, size_t off) noexcept
666+
[[msvc::forceinline]] void ROW::WriteHelper::_replaceTextUnicode(size_t ch, std::wstring_view::const_iterator it) noexcept
666667
{
667668
auto& cwd = CodepointWidthDetector::Singleton();
668-
const auto len = chars.size();
669669

670670
// Check if the new text joins with the existing contents of the row to form a single grapheme cluster.
671-
if (off == 0)
671+
if (it == chars.begin())
672672
{
673673
auto colPrev = colBeg;
674674
while (colPrev > 0 && row._uncheckedIsTrailer(--colPrev))
@@ -706,7 +706,7 @@ catch (...)
706706
}
707707

708708
ch += state.len;
709-
off += state.len;
709+
it += state.len;
710710
}
711711
}
712712
else
@@ -716,35 +716,38 @@ catch (...)
716716
// and let MeasureNext() find the next proper grapheme boundary.
717717
--colEnd;
718718
--ch;
719-
--off;
719+
--it;
720720
}
721721

722-
GraphemeState state{ .beg = chars.data() + off };
723-
724-
while (off < len)
722+
if (const auto end = chars.end(); it != end)
725723
{
726-
cwd.GraphemeNext(state, chars);
724+
GraphemeState state{ .beg = &*it };
727725

728-
const auto colEndNew = gsl::narrow_cast<uint16_t>(colEnd + state.width);
729-
if (colEndNew > colLimit)
726+
do
730727
{
731-
colEndDirty = colLimit;
732-
charsConsumed = ch - chBeg;
733-
return;
734-
}
728+
cwd.GraphemeNext(state, chars);
735729

736-
// Fill our char-offset buffer with 1 entry containing the mapping from the
737-
// current column (colEnd) to the start of the glyph in the string (ch)...
738-
til::at(row._charOffsets, colEnd++) = gsl::narrow_cast<uint16_t>(ch);
739-
// ...followed by 0-N entries containing an indication that the
740-
// columns are just a wide-glyph extension of the preceding one.
741-
while (colEnd < colEndNew)
742-
{
743-
til::at(row._charOffsets, colEnd++) = gsl::narrow_cast<uint16_t>(ch | CharOffsetsTrailer);
744-
}
730+
const auto colEndNew = gsl::narrow_cast<uint16_t>(colEnd + state.width);
731+
if (colEndNew > colLimit)
732+
{
733+
colEndDirty = colLimit;
734+
charsConsumed = ch - chBeg;
735+
return;
736+
}
745737

746-
ch += state.len;
747-
off += state.len;
738+
// Fill our char-offset buffer with 1 entry containing the mapping from the
739+
// current column (colEnd) to the start of the glyph in the string (ch)...
740+
til::at(row._charOffsets, colEnd++) = gsl::narrow_cast<uint16_t>(ch);
741+
// ...followed by 0-N entries containing an indication that the
742+
// columns are just a wide-glyph extension of the preceding one.
743+
while (colEnd < colEndNew)
744+
{
745+
til::at(row._charOffsets, colEnd++) = gsl::narrow_cast<uint16_t>(ch | CharOffsetsTrailer);
746+
}
747+
748+
ch += state.len;
749+
it += state.len;
750+
} while (it != end);
748751
}
749752

750753
colEndDirty = colEnd;

src/buffer/out/Row.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ROW final
186186
bool IsValid() const noexcept;
187187
void ReplaceCharacters(til::CoordType width) noexcept;
188188
void ReplaceText() noexcept;
189-
void _replaceTextUnicode(size_t ch, size_t off) noexcept;
189+
void _replaceTextUnicode(size_t ch, std::wstring_view::const_iterator it) noexcept;
190190
void CopyTextFrom(const std::span<const uint16_t>& charOffsets) noexcept;
191191
static void _copyOffsets(uint16_t* dst, const uint16_t* src, uint16_t size, uint16_t offset) noexcept;
192192
void Finish();

0 commit comments

Comments
 (0)