aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/diff.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-10-24 16:45:26 +0100
committerLewis Russell <lewis6991@gmail.com>2022-10-25 10:05:53 +0100
commit49c2da432bc4bef37903b0eda2ec8d26bdcb9c8b (patch)
treeefc17229885791a259cb5cc5a134a834ab48eac0 /src/nvim/diff.c
parent6da2271a04540f6f3bd6d3cae1895bb1ea1b5011 (diff)
downloadrneovim-49c2da432bc4bef37903b0eda2ec8d26bdcb9c8b.tar.gz
rneovim-49c2da432bc4bef37903b0eda2ec8d26bdcb9c8b.tar.bz2
rneovim-49c2da432bc4bef37903b0eda2ec8d26bdcb9c8b.zip
refactor(diff.c): factor out diffblock deletion
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r--src/nvim/diff.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 87ead61c36..1c68bad9a8 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -462,9 +462,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
dprev->df_count[i] += dp->df_count[i];
}
}
- dprev->df_next = dp->df_next;
- xfree(dp);
- dp = dprev->df_next;
+ dp = diff_free(tp, dprev, dp);
} else {
// Advance to next entry.
dprev = dp;
@@ -485,15 +483,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
}
if (i == DB_COUNT) {
- diff_T *dnext = dp->df_next;
- xfree(dp);
- dp = dnext;
-
- if (dprev == NULL) {
- tp->tp_first_diff = dnext;
- } else {
- dprev->df_next = dnext;
- }
+ dp = diff_free(tp, dprev, dp);
} else {
// Advance to next entry.
dprev = dp;
@@ -533,6 +523,20 @@ static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp)
return dnew;
}
+static diff_T *diff_free(tabpage_T *tp, diff_T *dprev, diff_T *dp)
+{
+ diff_T *ret = dp->df_next;
+ xfree(dp);
+
+ if (dprev == NULL) {
+ tp->tp_first_diff = ret;
+ } else {
+ dprev->df_next = ret;
+ }
+
+ return ret;
+}
+
/// Check if the diff block "dp" can be made smaller for lines at the start and
/// end that are equal. Called after inserting lines.
///
@@ -2777,13 +2781,6 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
if (i == DB_COUNT) {
// delete the diff entry, the buffers are now equal here
dfree = dp;
- dp = dp->df_next;
-
- if (dprev == NULL) {
- curtab->tp_first_diff = dp;
- } else {
- dprev->df_next = dp;
- }
}
}
@@ -2802,10 +2799,10 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
}
changed_lines(lnum, 0, lnum + count, added, true);
- if (dfree != NULL) {
+ if (dfree == dp) {
// Diff is deleted, update folds in other windows.
diff_fold_update(dfree, idx_to);
- xfree(dfree);
+ dp = diff_free(curtab, dprev, dp);
}
// mark_adjust() may have made "dp" invalid. We don't know where