It might worth to bring back old manually expanded code for SelectionPosition::operator <= and operator >= (used by Contains() and ContainsCharacter()), Clang and MSVC seems honor other == *this and think that's the likely case, then do a literal compile, result in four comparisons instead of just two, see https://godbolt.org/z/qnvePMaYh
direct expansion with virtualSpace comparison merged:
SelectionRange::Contains(Sci::Position pos) and SelectionRange::ContainsCharacter(Sci::Position posCharacter) seems can be simplified to if (anchor.Position() > caret.Position()) as virtualSpace isn't used for further comparison.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Range::ContainsCharacter()andSelectionRange::ContainsCharacter(Sci::Position posCharacter)can be simplified to unreadable((pos - start) * (pos - end)) < 0or((pos - start) ^ (pos - end)) < 0.Not worth the weirdness. The multiply version may overflow on huge documents.
Yeah, both may introduce new UB when either number is
PTRDIFF_MIN, https://alive2.llvm.org/ce/z/4eA5gvCommitted with [dea670] and [230a0b].
Related
Commit: [230a0b]
Commit: [dea670]
It might worth to bring back old manually expanded code for
SelectionPosition::operator <=andoperator >=(used byContains()andContainsCharacter()), Clang and MSVC seems honorother == *thisand think that's the likely case, then do a literal compile, result in four comparisons instead of just two, see https://godbolt.org/z/qnvePMaYhdirect expansion with
virtualSpacecomparison merged:or equivalents that MSVC generate small code. also looks close to
operator <andoperator >with just compare operator replaced.SelectionRange::Contains(Sci::Position pos)andSelectionRange::ContainsCharacter(Sci::Position posCharacter)seems can be simplified toif (anchor.Position() > caret.Position())asvirtualSpaceisn't used for further comparison.