From 312ce8312706da9afc8c16f49e684afdc752326a Mon Sep 17 00:00:00 2001 From: Hiers Date: Mon, 18 Dec 2023 07:52:33 +0000 Subject: [PATCH] Not sure if this actually improves performance. But just in case. --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72e005c..afbdc77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,7 @@ fn main() -> Result<(), ureq::Error> { let options = parse_args(); let mut query = String::new(); + let mut output = String::with_capacity(51200); /* Give output 50KiB of buffer; Should be enough to avoid reallocs*/ loop { query.clear(); @@ -62,7 +63,7 @@ fn main() -> Result<(), ureq::Error> { } let mut lines_output = 0; - let mut output = String::with_capacity(51200); /* Give output 50KiB of buffer; Should be enough to avoid reallocs*/ + output.clear(); if query.starts_with(':') || query.starts_with(':') { /* Kanji search */ /* if search_by_radical failed, then something is very wrong */ @@ -106,7 +107,7 @@ fn main() -> Result<(), ureq::Error> { if lines_output >= term_size - 1 && term_size != 0 { /* Output is a different process that is not a tty (i.e. less), but we want to keep colour */ env::set_var("CLICOLOR_FORCE", "1"); - pipe_to_less(output); + pipe_to_less(&output); } else { print!("{}", output); } @@ -155,7 +156,7 @@ fn parse_args() -> aux::Options { options } -fn pipe_to_less(output: String) { +fn pipe_to_less(output: &String) { let command = Command::new("less") .arg("-R")