Optimize release binary size

Also improve the $PWD watcher logic.
pull/138/head
Arijit Basu 3 years ago committed by Arijit Basu
parent 9597e78387
commit e9680d9abd

@ -36,3 +36,9 @@ criterion = "0.3"
[[bench]]
name = "criterion"
harness = false
# https://github.com/johnthagen/min-sized-rust
[profile.release]
lto = true
codegen-units = 1
panic = 'abort'

@ -5,7 +5,6 @@ use std::path::PathBuf;
use std::sync::mpsc::{Receiver, Sender};
use std::thread;
use std::time::Duration;
use std::time::SystemTime;
pub fn keep_watching(
pwd: &str,
@ -13,27 +12,28 @@ pub fn keep_watching(
rx_pwd_watcher: Receiver<String>,
) -> Result<()> {
let mut pwd = PathBuf::from(pwd);
let mut last_modified = pwd
.metadata()
.and_then(|m| m.modified())
.unwrap_or_else(|_| SystemTime::now());
let mut last_modified = pwd.metadata().and_then(|m| m.modified())?;
thread::spawn(move || loop {
if let Ok(new_pwd) = rx_pwd_watcher.try_recv() {
pwd = PathBuf::from(new_pwd);
} else {
let modified = pwd
.metadata()
pwd.metadata()
.and_then(|m| m.modified())
.unwrap_or_else(|_| SystemTime::now());
if modified != last_modified {
let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync);
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
last_modified = modified;
} else {
thread::sleep(Duration::from_millis(1000));
};
.map(|modified| {
if modified != last_modified {
let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync);
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
last_modified = modified;
} else {
thread::sleep(Duration::from_millis(1000));
};
})
.unwrap_or_else(|e| {
let msg = MsgIn::External(ExternalMsg::LogError(e.to_string()));
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
thread::sleep(Duration::from_millis(1000));
})
}
});
Ok(())

Loading…
Cancel
Save