mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Add default value to layout.threads in prefs.rs (fix15638)
This commit is contained in:
parent
973bf7af40
commit
b055e07aa7
1 changed files with 14 additions and 2 deletions
|
@ -3,10 +3,12 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use basedir::default_config_dir;
|
use basedir::default_config_dir;
|
||||||
|
use num_cpus;
|
||||||
use opts;
|
use opts;
|
||||||
use resource_files::resources_dir_path;
|
use resource_files::resources_dir_path;
|
||||||
use rustc_serialize::json::{Json, ToJson};
|
use rustc_serialize::json::{Json, ToJson};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use std::cmp::max;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write, stderr};
|
use std::io::{Read, Write, stderr};
|
||||||
|
@ -15,8 +17,11 @@ use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref PREFS: Preferences = {
|
pub static ref PREFS: Preferences = {
|
||||||
let prefs = read_prefs().ok().unwrap_or_else(HashMap::new);
|
let defaults = default_prefs();
|
||||||
Preferences(Arc::new(RwLock::new(prefs)))
|
if let Ok(prefs) = read_prefs() {
|
||||||
|
defaults.extend(prefs);
|
||||||
|
}
|
||||||
|
defaults
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +149,13 @@ impl ToJson for Pref {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_prefs() -> Preferences {
|
||||||
|
let prefs = Preferences(Arc::new(RwLock::new(HashMap::new())));
|
||||||
|
prefs.set("layout.threads", PrefValue::Number(
|
||||||
|
max(num_cpus::get() * 3 / 4, 1) as f64));
|
||||||
|
prefs
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_prefs_from_file<T>(mut file: T)
|
pub fn read_prefs_from_file<T>(mut file: T)
|
||||||
-> Result<HashMap<String, Pref>, ()> where T: Read {
|
-> Result<HashMap<String, Pref>, ()> where T: Read {
|
||||||
let json = try!(Json::from_reader(&mut file).or_else(|e| {
|
let json = try!(Json::from_reader(&mut file).or_else(|e| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue