@@ -641,34 +641,34 @@ catch (...)
641
641
//
642
642
// We can infer the "end" from the amount of columns we're given (colLimit - colBeg),
643
643
// 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);
645
646
size_t ch = chBeg;
646
- size_t off = 0 ;
647
647
648
- for (; off < len; ++off )
648
+ while (it != end )
649
649
{
650
- if (chars[off] >= 0x80 ) [[unlikely]]
650
+ if (*it >= 0x80 ) [[unlikely]]
651
651
{
652
- _replaceTextUnicode (ch, off );
652
+ _replaceTextUnicode (ch, it );
653
653
return ;
654
654
}
655
655
656
656
til::at (row._charOffsets , colEnd) = gsl::narrow_cast<uint16_t >(ch);
657
657
++colEnd;
658
658
++ch;
659
+ ++it;
659
660
}
660
661
661
662
colEndDirty = colEnd;
662
663
charsConsumed = ch - chBeg;
663
664
}
664
665
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
666
667
{
667
668
auto & cwd = CodepointWidthDetector::Singleton ();
668
- const auto len = chars.size ();
669
669
670
670
// 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 () )
672
672
{
673
673
auto colPrev = colBeg;
674
674
while (colPrev > 0 && row._uncheckedIsTrailer (--colPrev))
@@ -706,7 +706,7 @@ catch (...)
706
706
}
707
707
708
708
ch += state.len ;
709
- off += state.len ;
709
+ it += state.len ;
710
710
}
711
711
}
712
712
else
@@ -716,35 +716,38 @@ catch (...)
716
716
// and let MeasureNext() find the next proper grapheme boundary.
717
717
--colEnd;
718
718
--ch;
719
- --off ;
719
+ --it ;
720
720
}
721
721
722
- GraphemeState state{ .beg = chars.data () + off };
723
-
724
- while (off < len)
722
+ if (const auto end = chars.end (); it != end)
725
723
{
726
- cwd. GraphemeNext ( state, chars) ;
724
+ GraphemeState state{ . beg = &*it } ;
727
725
728
- const auto colEndNew = gsl::narrow_cast<uint16_t >(colEnd + state.width );
729
- if (colEndNew > colLimit)
726
+ do
730
727
{
731
- colEndDirty = colLimit;
732
- charsConsumed = ch - chBeg;
733
- return ;
734
- }
728
+ cwd.GraphemeNext (state, chars);
735
729
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
+ }
745
737
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);
748
751
}
749
752
750
753
colEndDirty = colEnd;
0 commit comments