Skip to content

Commit

Permalink
doc: refine use of the word 'unsafe'
Browse files Browse the repository at this point in the history
This removes extraneous commentary that uses the word 'unsafe'. This
makes it easier to grep for usages of meaningful 'unsafe' in the code.
  • Loading branch information
BurntSushi committed Mar 12, 2021
1 parent 691ec58 commit 5107293
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/backtrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<'a, 'm, 'r, 's, I: Input> Bounded<'a, 'm, 'r, 's, I> {
// Then we reset all existing allocated space to 0.
// Finally, we request more space if we need it.
//
// This is all a little circuitous, but doing this unsafely
// doesn't seem to have a measurable impact on performance.
// This is all a little circuitous, but doing this using unchecked
// operations doesn't seem to have a measurable impact on performance.
// (Probably because backtracking is limited to such small
// inputs/regexes in the first place.)
let visited_len =
Expand Down
4 changes: 2 additions & 2 deletions src/dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl<'a> Fsm<'a> {
/// next_si transitions to the next state, where the transition input
/// corresponds to text[i].
///
/// This elides bounds checks, and is therefore unsafe.
/// This elides bounds checks, and is therefore not safe.
#[cfg_attr(feature = "perf-inline", inline(always))]
unsafe fn next_si(&self, si: StatePtr, text: &[u8], i: usize) -> StatePtr {
// What is the argument for safety here?
Expand Down Expand Up @@ -1688,7 +1688,7 @@ impl Transitions {
self.num_byte_classes * mem::size_of::<StatePtr>()
}

/// Like `next`, but uses unchecked access and is therefore unsafe.
/// Like `next`, but uses unchecked access and is therefore not safe.
unsafe fn next_unchecked(&self, si: StatePtr, cls: usize) -> StatePtr {
debug_assert!((si as usize) < self.table.len());
debug_assert!(cls < self.num_byte_classes);
Expand Down
3 changes: 2 additions & 1 deletion src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ fn find_cap_ref(replacement: &[u8]) -> Option<CaptureRef> {
}
// We just verified that the range 0..cap_end is valid ASCII, so it must
// therefore be valid UTF-8. If we really cared, we could avoid this UTF-8
// check with either unsafe or by parsing the number straight from &[u8].
// check via an unchecked conversion or by parsing the number straight from
// &[u8].
let cap =
str::from_utf8(&rep[i..cap_end]).expect("valid UTF-8 capture name");
Some(CaptureRef {
Expand Down

0 comments on commit 5107293

Please sign in to comment.