Skip to content

Commit

Permalink
perf: use writeln! for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jan 4, 2023
1 parent b7d641b commit 80addf6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/output.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::{self, Write};
use std::path::PathBuf;

use log::trace;
Expand Down Expand Up @@ -28,10 +29,10 @@ impl Printer {
let response = dns::query(&self.domain, self.record_type, &server.ip);
trace!("Response -> {:?}", response);

println!("{}", server.name);
writeln!(io::stdout(), "{}", server.name).ok();
match response {
Err(e) => {
println!(" {}", e.to_string().red());
writeln!(io::stdout(), " {}", e.to_string().red()).ok();
}
Ok(res) => {
if !res.answers().is_empty() {
Expand All @@ -45,7 +46,7 @@ impl Printer {
}
} else {
// if default doesn't exist
println!("{}", " No zone found".to_string().red());
writeln!(io::stdout(), "{}", " No zone found".to_string().red()).ok();
}
}
}
Expand All @@ -60,6 +61,13 @@ impl Printer {
None => "".to_string(),
};
let rdata = rdata.bold();
println!(" {} {} {}", record_type.green().bold(), name.blue(), rdata);
writeln!(
io::stdout(),
" {} {} {}",
record_type.green().bold(),
name.blue(),
rdata
)
.ok();
}
}

0 comments on commit 80addf6

Please sign in to comment.