perf: further cow with_final_newline #86

Merged
wetneb merged 1 commit from ada4a/mergiraf:more_cow into main 2024-12-08 09:18:53 +01:00

View file

@ -42,7 +42,7 @@ pub(crate) mod tree_builder;
pub(crate) mod tree_matcher;
pub(crate) mod visualizer;
use std::{fs, path::Path, time::Instant};
use std::{borrow::Cow, fs, path::Path, time::Instant};
use attempts::AttemptsCache;
use git::extract_revision_from_git;
@ -153,8 +153,10 @@ pub fn structured_merge(
);
debug!("{result_tree}");
let result = Cow::from(result_tree.pretty_print(&class_mapping, settings));
Ok(MergeResult {
contents: with_final_newline(&result_tree.pretty_print(&class_mapping, settings)).into(),
contents: with_final_newline(result).into_owned(),
conflict_count: result_tree.count_conflicts(),
conflict_mass: result_tree.conflict_mass(),
method: if parsed_merge.is_none() {
@ -251,9 +253,9 @@ fn line_based_merge_with_duplicate_signature_detection(
lang_profile: Option<&LangProfile>,
) -> MergeResult {
let mut line_based_merge = line_based_merge(
&with_final_newline(contents_base),
&with_final_newline(contents_left),
&with_final_newline(contents_right),
&with_final_newline(Cow::from(contents_base)),
&with_final_newline(Cow::from(contents_left)),
&with_final_newline(Cow::from(contents_right)),
settings,
);

View file

@ -25,11 +25,11 @@ pub const STRUCTURED_RESOLUTION_METHOD: &str = "structured_resolution";
pub const FULLY_STRUCTURED_METHOD: &str = "fully_structured";
/// Ensures a given string has a newline at the end.
pub(crate) fn with_final_newline(s: &str) -> Cow<str> {
pub(crate) fn with_final_newline(s: Cow<str>) -> Cow<str> {
if s.ends_with('\n') {
Cow::from(s)
s
} else {
Cow::from(s.to_string() + "\n")
s + "\n"
}
}