Skip to content

Commit

Permalink
Improve performance by reducing log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed May 18, 2024
1 parent 28e6f5c commit a0ca55c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 35 deletions.
43 changes: 25 additions & 18 deletions src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ pub fn apply_indent(
logs: &mut Vec<Log>,
pass: Option<usize>,
) -> String {
record_log(
logs,
Info,
pass,
filename.to_string(),
None,
None,
format!("Indent pass {}.", pass.unwrap()),
);
if args.verbose {
record_log(
logs,
Info,
pass,
filename.to_string(),
None,
None,
format!("Indent pass {}.", pass.unwrap()),
);
}

let mut indent = Indent::new();
let mut ignore = Ignore::new();
Expand All @@ -136,15 +138,20 @@ pub fn apply_indent(
let comment_index = find_comment_index(line);
let line_strip = remove_comment(line, comment_index);
indent = get_indent(line_strip, indent);
record_log(
logs,
Info,
pass,
filename.to_string(),
Some(linum),
Some(line.to_string()),
format!("Indent: actual = {}, visual = {}", indent.actual, indent.visual),
);
if args.verbose {
record_log(
logs,
Info,
pass,
filename.to_string(),
Some(linum),
Some(line.to_string()),
format!(
"Indent: actual = {}, visual = {}",
indent.actual, indent.visual
),
);
}

if (indent.visual < 0) || (indent.actual < 0) {
record_log(
Expand Down
11 changes: 7 additions & 4 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use log::Level;
use log::Level::{Error, Info, Warn};
use log::LevelFilter;
use std::io::Write;
use std::time::Instant;
use std::path::Path;
use std::time::Instant;

#[derive(Debug)]
pub struct Log {
Expand Down Expand Up @@ -73,8 +73,7 @@ pub fn init_logger(args: &Cli) {
}

pub fn print_logs(args: &Cli, mut logs: Vec<Log>) {

if get_log_level(args) == LevelFilter::Warn {
if get_log_level(args) == LevelFilter::Warn && !logs.is_empty() {
let max_pass = &logs.iter().map(|l| l.pass).max().unwrap();
logs.retain(|l| l.pass == *max_pass || l.pass == None);
}
Expand All @@ -96,7 +95,11 @@ pub fn print_logs(args: &Cli, mut logs: Vec<Log>) {
"{}tex-fmt {}{}: {}{}{}{} {}{:.50}",
PINK,
PURPLE,
Path::new(&log.filename).file_name().unwrap().to_str().unwrap(),
Path::new(&log.filename)
.file_name()
.unwrap()
.to_str()
.unwrap(),
WHITE,
linum,
YELLOW,
Expand Down
21 changes: 11 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ fn main() {
init_logger(&args);

for filename in &args.filenames {

let mut logs: Vec<Log> = vec![];
record_log(
&mut logs,
Info,
None,
filename.to_string(),
None,
None,
"Begin indenting.".to_string(),
);
if args.verbose {
record_log(
&mut logs,
Info,
None,
filename.to_string(),
None,
None,
"Begin indenting.".to_string(),
);
}

let extension_valid = check_extension_valid(filename);
if extension_valid {
Expand Down
4 changes: 2 additions & 2 deletions src/print.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//use crate::colors::*;

//pub fn print_script_name() {
//println!("{}tex-fmt{}", PINK, RESET);
//println!("{}tex-fmt{}", PINK, RESET);
//}

//pub fn print_filename(filename: &str) {
//println!("{}{}{}", PURPLE, filename, RESET);
//println!("{}{}{}", PURPLE, filename, RESET);
//}

pub fn print_file(new_file: &str) {
Expand Down
7 changes: 6 additions & 1 deletion src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ fn wrap_line(line: &str) -> String {
new_line
}

pub fn wrap(file: &str, filename: &str, logs: &mut Vec<Log>, pass: Option<usize>) -> String {
pub fn wrap(
file: &str,
filename: &str,
logs: &mut Vec<Log>,
pass: Option<usize>,
) -> String {
//log::info!("Wrapping file");
let mut new_file = "".to_string();
let mut new_line: String;
Expand Down

0 comments on commit a0ca55c

Please sign in to comment.