Эх сурвалжийг харах

Auto merge of #401 - servo:revert, r=SimonSapin

Revert "Remove unnecessary bounds checking in a couple places."

This reverts commit d3dfbf3123258fe27649dc74f0dd07a14a5801b2.

Let’s not add `unsafe` code gratuitously.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/401)
<!-- Reviewable:end -->
bors-servo 9 жил өмнө
parent
commit
73fc76ec06

+ 5 - 7
src/form_urlencoded.rs

@@ -64,7 +64,7 @@ pub fn parse_with_encoding<'a>(input: &'a [u8],
         for sequence in input.split(|&b| b == b'&') {
         for sequence in input.split(|&b| b == b'&') {
             // No '+' in "_charset_" to replace with ' '.
             // No '+' in "_charset_" to replace with ' '.
             if sequence.starts_with(b"_charset_=") {
             if sequence.starts_with(b"_charset_=") {
-                let value = unsafe { &sequence.get_unchecked(b"_charset_=".len()..) };
+                let value = &sequence[b"_charset_=".len()..];
                 // Skip replacing '+' with ' ' in value since no encoding label contains either:
                 // Skip replacing '+' with ' ' in value since no encoding label contains either:
                 // https://encoding.spec.whatwg.org/#names-and-labels
                 // https://encoding.spec.whatwg.org/#names-and-labels
                 if let Some(e) = EncodingOverride::lookup(value) {
                 if let Some(e) = EncodingOverride::lookup(value) {
@@ -126,12 +126,10 @@ fn replace_plus(input: &[u8]) -> Cow<[u8]> {
         None => Cow::Borrowed(input),
         None => Cow::Borrowed(input),
         Some(first_position) => {
         Some(first_position) => {
             let mut replaced = input.to_owned();
             let mut replaced = input.to_owned();
-            unsafe {
-                *replaced.get_unchecked_mut(first_position) = b' ';
-                for byte in replaced.get_unchecked_mut(first_position + 1..) {
-                    if *byte == b'+' {
-                        *byte = b' ';
-                    }
+            replaced[first_position] = b' ';
+            for byte in &mut replaced[first_position + 1..] {
+                if *byte == b'+' {
+                    *byte = b' ';
                 }
                 }
             }
             }
             Cow::Owned(replaced)
             Cow::Owned(replaced)