text: Downgrade some more offset panics to error logs (#43925)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -220,7 +220,11 @@ impl<'a> ChunkSlice<'a> {
|
||||
range.start = self.text.ceil_char_boundary(range.start);
|
||||
}
|
||||
if !self.assert_char_boundary::<false>(range.end) {
|
||||
range.end = self.text.floor_char_boundary(range.end);
|
||||
range.end = if range.end < range.start {
|
||||
range.start
|
||||
} else {
|
||||
self.text.floor_char_boundary(range.end)
|
||||
};
|
||||
}
|
||||
let mask = (1 as Bitmap)
|
||||
.unbounded_shl(range.end as u32)
|
||||
|
||||
+12
-4
@@ -50,23 +50,31 @@ impl Rope {
|
||||
|
||||
#[track_caller]
|
||||
#[inline(always)]
|
||||
pub fn assert_char_boundary(&self, offset: usize) {
|
||||
pub fn assert_char_boundary<const PANIC: bool>(&self, offset: usize) -> bool {
|
||||
if self.chunks.is_empty() && offset == 0 {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
let (start, _, item) = self.chunks.find::<usize, _>((), &offset, Bias::Left);
|
||||
match item {
|
||||
Some(chunk) => {
|
||||
let chunk_offset = offset - start;
|
||||
chunk.assert_char_boundary::<true>(chunk_offset);
|
||||
chunk.assert_char_boundary::<PANIC>(chunk_offset)
|
||||
}
|
||||
None => {
|
||||
None if PANIC => {
|
||||
panic!(
|
||||
"byte index {} is out of bounds of rope (length: {})",
|
||||
offset,
|
||||
self.len()
|
||||
);
|
||||
}
|
||||
None => {
|
||||
log::error!(
|
||||
"byte index {} is out of bounds of rope (length: {})",
|
||||
offset,
|
||||
self.len()
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user