• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moonbitlang / core / 5796

07 Aug 2026 02:57AM UTC coverage: 90.321% (+0.009%) from 90.312%
5796

push

github

bobzhang
perf(string): back code unit range comparison with %string.unsafe_range_equal

Add a private `String::unsafe_range_equal` primitive, annotated with
`#intrinsic("%string.unsafe_range_equal")` and `#borrow`, mirroring the
existing `Bytes::unsafe_range_equal`. The MoonBit body is the fallback for
backends without the intrinsic; on native it lowers to a single `memcmp`.

Route the hand-rolled code unit loops through it: `StringView::has_prefix`,
`StringView::has_suffix`, `Eq for StringView` and
`StringView::equal_to_string`.

`has_prefix`/`has_suffix` compare the anchor code unit inline before the
call, because rejecting there is the common case and is cheaper than the
range-compare call overhead.

The `find`/`rev_find` two-anchor middle check is deliberately left on the
inline early-exit loop: its ranges are short and usually mismatch early, so
the call overhead dominates.

16228 of 17967 relevant lines covered (90.32%)

168740.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.14
/builtin/stringview.mbt


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc