servo: Merge #14181 - Don't unnecessarily clone entire `opts::Opt` structure (from frewsxcv:opt-clone); r=nox
authorCorey Farwell <coreyf@rwell.org>
Sat, 12 Nov 2016 05:56:59 -0600
changeset 340138 77c07e9b9dadb6ed1abea9281daa645f733331b3
parent 340137 8a703a73f48ce980484a52153749d71301fb1ff8
child 340139 e7c357e94e3065c10c28efea382865eaa2d4ca41
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)
reviewersnox
servo: Merge #14181 - Don't unnecessarily clone entire `opts::Opt` structure (from frewsxcv:opt-clone); r=nox `opts::Opt` is a pretty big structure, so cloning everything is excessive when we only need a few items. Source-Repo: https://github.com/servo/servo Source-Revision: 2d0c7166f118efed9f25fbe7b4f01f9521829418
servo/components/servo/lib.rs
servo/components/util/opts.rs
--- a/servo/components/servo/lib.rs
+++ b/servo/components/servo/lib.rs
@@ -82,19 +82,22 @@ use log::{Log, LogMetadata, LogRecord};
 use net::image_cache_thread::new_image_cache_thread;
 use net::resource_thread::new_resource_threads;
 use net_traits::IpcSend;
 use profile::mem as profile_mem;
 use profile::time as profile_time;
 use profile_traits::mem;
 use profile_traits::time;
 use script_traits::{ConstellationMsg, SWManagerSenders, ScriptMsg};
+use std::borrow::Cow;
 use std::cmp::max;
+use std::path::PathBuf;
 use std::rc::Rc;
 use std::sync::mpsc::Sender;
+use url::Url;
 use util::opts;
 use util::prefs::PREFS;
 use util::resource_files::resources_dir_path;
 
 pub use gleam::gl;
 
 /// The in-process interface to Servo.
 ///
@@ -172,17 +175,19 @@ impl<Window> Browser<Window> where Windo
 
         // Important that this call is done in a single-threaded fashion, we
         // can't defer it after `create_constellation` has started.
         script::init();
 
         // Create the constellation, which maintains the engine
         // pipelines, including the script and layout threads, as well
         // as the navigation context.
-        let (constellation_chan, sw_senders) = create_constellation(opts.clone(),
+        let (constellation_chan, sw_senders) = create_constellation(opts.user_agent.clone(),
+                                                                    opts.config_dir.clone(),
+                                                                    opts.url.clone(),
                                                                     compositor_proxy.clone_compositor_proxy(),
                                                                     time_profiler_chan.clone(),
                                                                     mem_profiler_chan.clone(),
                                                                     debugger_chan,
                                                                     devtools_chan,
                                                                     supports_clipboard,
                                                                     webrender_api_sender.clone());
 
@@ -237,32 +242,34 @@ impl<Window> Browser<Window> where Windo
             let filter = max(env_logger.filter(), con_logger.filter());
             let logger = BothLogger(env_logger, con_logger);
             max_log_level.set(filter);
             Box::new(logger)
         }).expect("Failed to set logger.")
     }
 }
 
-fn create_constellation(opts: opts::Opts,
+fn create_constellation(user_agent: Cow<'static, str>,
+                        config_dir: Option<PathBuf>,
+                        url: Option<Url>,
                         compositor_proxy: Box<CompositorProxy + Send>,
                         time_profiler_chan: time::ProfilerChan,
                         mem_profiler_chan: mem::ProfilerChan,
                         debugger_chan: Option<debugger::Sender>,
                         devtools_chan: Option<Sender<devtools_traits::DevtoolsControlMsg>>,
                         supports_clipboard: bool,
                         webrender_api_sender: webrender_traits::RenderApiSender)
                         -> (Sender<ConstellationMsg>, SWManagerSenders) {
     let bluetooth_thread: IpcSender<BluetoothRequest> = BluetoothThreadFactory::new();
 
     let (public_resource_threads, private_resource_threads) =
-        new_resource_threads(opts.user_agent,
+        new_resource_threads(user_agent,
                              devtools_chan.clone(),
                              time_profiler_chan.clone(),
-                             opts.config_dir.map(Into::into));
+                             config_dir);
     let image_cache_thread = new_image_cache_thread(public_resource_threads.sender(),
                                                     webrender_api_sender.create_api());
     let font_cache_thread = FontCacheThread::new(public_resource_threads.sender(),
                                                  Some(webrender_api_sender.create_api()));
 
     let resource_sender = public_resource_threads.sender();
 
     let initial_state = InitialConstellationState {
@@ -279,17 +286,17 @@ fn create_constellation(opts: opts::Opts
         supports_clipboard: supports_clipboard,
         webrender_api_sender: webrender_api_sender,
     };
     let (constellation_chan, from_swmanager_sender) =
         Constellation::<script_layout_interface::message::Msg,
                         layout_thread::LayoutThread,
                         script::script_thread::ScriptThread>::start(initial_state);
 
-    if let Some(url) = opts.url {
+    if let Some(url) = url {
         constellation_chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap();
     };
 
     // channels to communicate with Service Worker Manager
     let sw_senders = SWManagerSenders {
         swmanager_sender: from_swmanager_sender,
         resource_sender: resource_sender
     };
--- a/servo/components/util/opts.rs
+++ b/servo/components/util/opts.rs
@@ -210,17 +210,17 @@ pub struct Opts {
     /// useful when modifying the shaders, to ensure they all compile
     /// after each change is made.
     pub precache_shaders: bool,
 
     /// True if WebRender should use multisample antialiasing.
     pub use_msaa: bool,
 
     /// Directory for a default config directory
-    pub config_dir: Option<String>,
+    pub config_dir: Option<PathBuf>,
 
     // don't skip any backtraces on panic
     pub full_backtraces: bool,
 
     /// True to use OS native signposting facilities. This makes profiling events (script activity,
     /// reflow, compositing, etc.) appear in Instruments.app on macOS.
     pub signpost: bool,
 
@@ -852,17 +852,17 @@ pub fn from_cmdline_args(args: &[String]
         disable_share_style_cache: debug_options.disable_share_style_cache,
         style_sharing_stats: debug_options.style_sharing_stats,
         convert_mouse_to_touch: debug_options.convert_mouse_to_touch,
         exit_after_load: opt_match.opt_present("x"),
         no_native_titlebar: do_not_use_native_titlebar,
         enable_vsync: !debug_options.disable_vsync,
         webrender_stats: debug_options.webrender_stats,
         use_msaa: debug_options.use_msaa,
-        config_dir: opt_match.opt_str("config-dir"),
+        config_dir: opt_match.opt_str("config-dir").map(Into::into),
         full_backtraces: debug_options.full_backtraces,
         is_printing_version: is_printing_version,
         webrender_debug: debug_options.webrender_debug,
         precache_shaders: debug_options.precache_shaders,
         signpost: debug_options.signpost,
     };
 
     set_defaults(opts);