perf: further cow with_final_newline
#86
2 changed files with 10 additions and 8 deletions
12
src/lib.rs
12
src/lib.rs
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue