Skip to content

Commit d3dfbf3

Browse files
committed
Remove unnecessary bounds checking in a couple places.
1 parent ebd789f commit d3dfbf3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/form_urlencoded.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn parse_with_encoding<'a>(input: &'a [u8],
6464
for sequence in input.split(|&b| b == b'&') {
6565
// No '+' in "_charset_" to replace with ' '.
6666
if sequence.starts_with(b"_charset_=") {
67-
let value = &sequence[b"_charset_=".len()..];
67+
let value = unsafe { &sequence.get_unchecked(b"_charset_=".len()..) };
6868
// Skip replacing '+' with ' ' in value since no encoding label contains either:
6969
// https://encoding.spec.whatwg.org/#names-and-labels
7070
if let Some(e) = EncodingOverride::lookup(value) {
@@ -126,10 +126,12 @@ fn replace_plus(input: &[u8]) -> Cow<[u8]> {
126126
None => Cow::Borrowed(input),
127127
Some(first_position) => {
128128
let mut replaced = input.to_owned();
129-
replaced[first_position] = b' ';
130-
for byte in &mut replaced[first_position + 1..] {
131-
if *byte == b'+' {
132-
*byte = b' ';
129+
unsafe {
130+
*replaced.get_unchecked_mut(first_position) = b' ';
131+
for byte in replaced.get_unchecked_mut(first_position + 1..) {
132+
if *byte == b'+' {
133+
*byte = b' ';
134+
}
133135
}
134136
}
135137
Cow::Owned(replaced)

0 commit comments

Comments
 (0)