From aa067e636bf1ed50e3a07b05104aa85dd9bed69d Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 17 Dec 2022 23:44:39 -0800 Subject: [PATCH] Don't bother storing bytes of binary files --- src/main.rs | 19 +++++++++---------- src/summary.rs | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2e97fc466..51c18d855 100644 --- a/src/main.rs +++ b/src/main.rs @@ -284,9 +284,8 @@ fn diff_file_content( rhs_display_path: rhs_display_path.into(), language: None, detected_language: None, - // TODO: do we need to store the actual bytes? - lhs_src: FileContent::Binary(lhs_bytes.to_vec()), - rhs_src: FileContent::Binary(rhs_bytes.to_vec()), + lhs_src: FileContent::Binary, + rhs_src: FileContent::Binary, lhs_positions: vec![], rhs_positions: vec![], hunks: vec![], @@ -539,9 +538,8 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) { } } } - (FileContent::Binary(lhs_bytes), FileContent::Binary(rhs_bytes)) => { - let changed = lhs_bytes != rhs_bytes; - if display_options.print_unchanged || changed { + (FileContent::Binary, FileContent::Binary) => { + if display_options.print_unchanged || !summary.has_same_bytes { println!( "{}", display::style::header( @@ -553,14 +551,15 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) { display_options ) ); - if changed { - println!("Binary contents changed."); - } else { + if summary.has_same_bytes { println!("No changes."); + } else { + println!("Binary contents changed."); } } } - (_, FileContent::Binary(_)) | (FileContent::Binary(_), _) => { + (FileContent::Text(_), FileContent::Binary) + | (FileContent::Binary, FileContent::Text(_)) => { // We're diffing a binary file against a text file. println!( "{}", diff --git a/src/summary.rs b/src/summary.rs index c8b2c7593..6a640459c 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -5,7 +5,7 @@ use crate::{display::hunks::Hunk, parse::syntax::MatchedPos}; #[derive(Debug, PartialEq, Eq)] pub enum FileContent { Text(String), - Binary(Vec), + Binary, } #[derive(Debug)]