Bug 1739536 - [mozdevice-rust] Replace manual prefix checks with starts_with. r=whimboo,webdriver-reviewers
authorkpcyrd <git@rxv.cc>
Mon, 08 Nov 2021 09:56:37 +0000
changeset 598485 683d1f1978e6dcde08d10b9d26f1dfa43a24a39c
parent 598484 602918a34ee624cc8d0fffb154280ca3cb794595
child 598486 2635e89a17901559baea7ba0e50adea0cbad8e42
push id38960
push usernbeleuzu@mozilla.com
push dateMon, 08 Nov 2021 16:38:54 +0000
treeherdermozilla-central@01a19f2bf0c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo, webdriver-reviewers
bugs1739536
milestone96.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1739536 - [mozdevice-rust] Replace manual prefix checks with starts_with. r=whimboo,webdriver-reviewers Depends on D130413 Differential Revision: https://phabricator.services.mozilla.com/D130414
testing/mozbase/rust/mozdevice/src/lib.rs
--- a/testing/mozbase/rust/mozdevice/src/lib.rs
+++ b/testing/mozbase/rust/mozdevice/src/lib.rs
@@ -157,37 +157,37 @@ fn write_length_little_endian(writer: &m
     writer.write(&bytes[..]).map_err(DeviceError::Io)
 }
 
 fn read_response(stream: &mut TcpStream, has_output: bool, has_length: bool) -> Result<Vec<u8>> {
     let mut bytes: [u8; 1024] = [0; 1024];
 
     stream.read_exact(&mut bytes[0..4])?;
 
-    if &bytes[0..4] != SyncCommand::Okay.code() {
+    if !bytes.starts_with(SyncCommand::Okay.code()) {
         let n = bytes.len().min(read_length(stream)?);
         stream.read_exact(&mut bytes[0..n])?;
 
         let message = std::str::from_utf8(&bytes[0..n]).map(|s| format!("adb error: {}", s))?;
 
         return Err(DeviceError::Adb(message));
     }
 
     let mut response = Vec::new();
 
     if has_output {
         stream.read_to_end(&mut response)?;
 
-        if response.len() >= 4 && &response[0..4] == SyncCommand::Okay.code() {
+        if response.starts_with(SyncCommand::Okay.code()) {
             // Sometimes the server produces OKAYOKAY.  Sometimes there is a transport OKAY and
             // then the underlying command OKAY.  This is straight from `chromedriver`.
             response = response.split_off(4);
         }
 
-        if response.len() >= 4 && &response[0..4] == SyncCommand::Fail.code() {
+        if response.starts_with(SyncCommand::Fail.code()) {
             // The server may even produce OKAYFAIL, which means the underlying
             // command failed. First split-off the `FAIL` and length of the message.
             response = response.split_off(8);
 
             let message = std::str::from_utf8(&*response).map(|s| format!("adb error: {}", s))?;
 
             return Err(DeviceError::Adb(message));
         }
@@ -747,30 +747,30 @@ impl Device {
             & 0xFFFF_FFFF) as u32;
 
         stream.write_all(SyncCommand::Done.code())?;
         write_length_little_endian(&mut stream, time as usize)?;
 
         // Status.
         stream.read_exact(&mut buf[0..4])?;
 
-        if &buf[0..4] == SyncCommand::Okay.code() {
+        if buf.starts_with(SyncCommand::Okay.code()) {
             if enable_run_as {
                 // Use cp -a to preserve the permissions set by push.
                 let result = self.execute_host_shell_command_as(
                     format!("cp -aR {} {}", dest1.display(), dest.display()).as_str(),
                     enable_run_as,
                 );
                 if self.remove(dest1).is_err() {
                     debug!("Failed to remove {}", dest1.display());
                 }
                 result?;
             }
             Ok(())
-        } else if &buf[0..4] == SyncCommand::Fail.code() {
+        } else if buf.starts_with(SyncCommand::Fail.code()) {
             if enable_run_as && self.remove(dest1).is_err() {
                 debug!("Failed to remove {}", dest1.display());
             }
             let n = buf.len().min(read_length_little_endian(&mut stream)?);
 
             stream.read_exact(&mut buf[0..n])?;
 
             let message = std::str::from_utf8(&buf[0..n])