diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs index 97c6dbc19..effd5a6bc 100644 --- a/src/utils/gen_util.rs +++ b/src/utils/gen_util.rs @@ -101,20 +101,19 @@ fn grapheme_width(g: &str) -> usize { fn truncate_str>(content: &str, width: U) -> String { let width = width.into(); - if width > 0 { + if content.len() <= width { + // If the entire string fits in the width, it'll definitely fit. + content.to_owned() + } else if width > 0 { if content.is_ascii() { // If the entire string is ASCII, we can use a much simpler approach. - if content.len() <= width { - content.to_owned() - } else { - let mut text = String::with_capacity(width); - let (keep, _throw) = content.split_at(width - 1); - text.push_str(keep); - text.push('…'); + let mut text = String::with_capacity(width); + let (keep, _throw) = content.split_at(width - 1); + text.push_str(keep); + text.push('…'); - text - } + text } else { let mut text = String::with_capacity(width); let mut curr_width = 0;