diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2024-03-28 20:27:12 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2024-04-13 17:03:12 +0200 |
| commit | 5039160c5bd16a9d4908c71b8941ff95e866125f (patch) | |
| tree | d8b726d3a7d0be25f458e56a3e3656bb267518a1 /compiler/rustc_span/src/span_encoding.rs | |
| parent | c3b05c6e5b5b59613350b8c2875b0add67ed74df (diff) | |
| download | rust-5039160c5bd16a9d4908c71b8941ff95e866125f.tar.gz rust-5039160c5bd16a9d4908c71b8941ff95e866125f.zip | |
Add add/sub methods that only panic with debug assertions to rustc
This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.
Diffstat (limited to 'compiler/rustc_span/src/span_encoding.rs')
| -rw-r--r-- | compiler/rustc_span/src/span_encoding.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index e162695a13b..788a52faf56 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -5,6 +5,10 @@ use crate::{BytePos, SpanData}; use rustc_data_structures::fx::FxIndexSet; +// This code is very hot and uses lots of arithmetic, avoid overflow checks for performance. +// See https://github.com/rust-lang/rust/pull/119440#issuecomment-1874255727 +use rustc_serialize::int_overflow::DebugStrictAdd; + /// A compressed span. /// /// [`SpanData`] is 16 bytes, which is too big to stick everywhere. `Span` only @@ -166,7 +170,7 @@ impl Span { debug_assert!(len <= MAX_LEN); SpanData { lo: BytePos(self.lo_or_index), - hi: BytePos(self.lo_or_index + len), + hi: BytePos(self.lo_or_index.debug_strict_add(len)), ctxt: SyntaxContext::from_u32(self.ctxt_or_parent_or_marker as u32), parent: None, } @@ -179,7 +183,7 @@ impl Span { }; SpanData { lo: BytePos(self.lo_or_index), - hi: BytePos(self.lo_or_index + len), + hi: BytePos(self.lo_or_index.debug_strict_add(len)), ctxt: SyntaxContext::root(), parent: Some(parent), } |
