diff --git a/src/main.rs b/src/main.rs index 61dc4b4..38f981d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -687,33 +687,16 @@ struct HunkHeader { plus_range: (usize, usize), } -const WIDTH: [u64; 20] = [ - 0, - 9, - 99, - 999, - 9999, - 99999, - 999999, - 9999999, - 99999999, - 999999999, - 9999999999, - 99999999999, - 999999999999, - 9999999999999, - 99999999999999, - 999999999999999, - 9999999999999999, - 99999999999999999, - 999999999999999999, - 9999999999999999999, -]; - fn width1(x: u64, st: Option) -> usize { - let result = WIDTH.binary_search(&x); - let result = match result { - Ok(i) | Err(i) => i, + let result = if x == 0 { + 0 + } else { + let mut counter = 1; + let mut x = x; + while x >= 10 { + (x, counter) = (x / 10, counter + 1); + } + counter }; st.map(|style| style.min_width()).unwrap_or(0).max(result) } diff --git a/src/tests_app.rs b/src/tests_app.rs index f59eaa5..b9ee3d9 100644 --- a/src/tests_app.rs +++ b/src/tests_app.rs @@ -65,11 +65,6 @@ fn parse_line_number_test() { #[test] fn test_width() { - for (i, x) in WIDTH.iter().enumerate() { - if x < &u64::max_value() { - assert_eq!(format!("{}", x + 1).len(), i + 1); - } - } assert_eq!(0, width1(0, None)); fn test(x: u64) { assert_eq!(format!("{}", x).len(), width1(x, None));