servo: Merge #13304 - Don't require `PathBuf` ownership if we don't need it (from frewsxcv:ownership); r=jdm
authorCorey Farwell <coreyf@rwell.org>
Fri, 16 Sep 2016 23:14:14 -0500
changeset 339698 c9b04982e2f0f4f27690c4581a4effc179a86e48
parent 339697 977f2caa675c38a086eb352483e008e19dc211f4
child 339699 e2e59b47c07cf52aa3845e106111c80b4b7e72ef
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #13304 - Don't require `PathBuf` ownership if we don't need it (from frewsxcv:ownership); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: 6ac9dfdd34299d284995f5e7f957f515f4a2c880
servo/components/net/file_loader.rs
--- a/servo/components/net/file_loader.rs
+++ b/servo/components/net/file_loader.rs
@@ -9,17 +9,17 @@ use msg::constellation_msg::{PipelineId,
 use net_traits::{LoadConsumer, LoadData, LoadOrigin, Metadata, NetworkError};
 use net_traits::ProgressMsg::{Done, Payload};
 use resource_thread::{CancellationListener, ProgressSender};
 use resource_thread::{send_error, start_sending_sniffed_opt};
 use std::borrow::ToOwned;
 use std::error::Error;
 use std::fs::File;
 use std::io::Read;
-use std::path::PathBuf;
+use std::path::Path;
 use std::sync::Arc;
 use url::Url;
 use util::thread::spawn_named;
 
 static READ_SIZE: usize = 8192;
 
 enum ReadStatus {
     Partial(Vec<u8>),
@@ -63,21 +63,21 @@ fn read_all(reader: &mut File, progress_
             ReadStatus::Partial(buf) => progress_chan.send(Payload(buf)).unwrap(),
             ReadStatus::EOF => return Ok(LoadResult::Finished),
         }
     }
     let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
     Ok(LoadResult::Cancelled)
 }
 
-fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
+fn get_progress_chan(load_data: LoadData, file_path: &Path,
                      senders: LoadConsumer, classifier: Arc<MimeClassifier>, buf: &[u8])
                      -> Result<ProgressSender, ()> {
     let mut metadata = Metadata::default(load_data.url);
-    let mime_type = guess_mime_type(file_path.as_path());
+    let mime_type = guess_mime_type(file_path);
     metadata.set_content_type(Some(&mime_type));
     return start_sending_sniffed_opt(senders, metadata, classifier, buf, load_data.context);
 }
 
 pub fn factory(load_data: LoadData,
                senders: LoadConsumer,
                classifier: Arc<MimeClassifier>,
                cancel_listener: CancellationListener) {
@@ -100,38 +100,38 @@ pub fn factory(load_data: LoadData,
                 let url = Url::parse("about:not-found").unwrap();
                 let load_data_404 = LoadData::new(load_data.context, url, &FileLoadOrigin);
                 about_loader::factory(load_data_404, senders, classifier, cancel_listener);
                 return;
             }
         };
 
         if cancel_listener.is_cancelled() {
-            if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
+            if let Ok(progress_chan) = get_progress_chan(load_data, &file_path,
                                                          senders, classifier, &[]) {
                 let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
             }
             return;
         }
 
         match read_block(reader) {
             Ok(ReadStatus::Partial(buf)) => {
-                let progress_chan = get_progress_chan(load_data, file_path,
+                let progress_chan = get_progress_chan(load_data, &file_path,
                                                       senders, classifier, &buf).ok().unwrap();
                 progress_chan.send(Payload(buf)).unwrap();
                 let read_result = read_all(reader, &progress_chan, &cancel_listener);
                 if let Ok(load_result) = read_result {
                     match load_result {
                         LoadResult::Cancelled => return,
                         LoadResult::Finished => progress_chan.send(Done(Ok(()))).unwrap(),
                     }
                 }
             }
             Ok(ReadStatus::EOF) => {
-                if let Ok(chan) = get_progress_chan(load_data, file_path,
+                if let Ok(chan) = get_progress_chan(load_data, &file_path,
                                                     senders, classifier, &[]) {
                     let _ = chan.send(Done(Ok(())));
                 }
             }
             Err(e) => {
                 send_error(load_data.url, NetworkError::Internal(e), senders);
             }
         }