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.
This commit is contained in:
parent
c3b05c6e5b
commit
5039160c5b
6 changed files with 109 additions and 27 deletions
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue