diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/intervals.c | 46 | ||||
-rw-r--r-- | src/mergesort.c | 2 |
2 files changed, 23 insertions, 25 deletions
diff --git a/src/intervals.c b/src/intervals.c index e2034132..dcc06d18 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -118,6 +118,26 @@ static bool merge_ranges(struct set_automerge_ctx *ctx, return false; } +static void set_sort_splice(struct expr *init, struct set *set) +{ + struct set *existing_set = set->existing_set; + + set_to_range(init); + list_expr_sort(&init->expressions); + + if (!existing_set) + return; + + if (existing_set->init) { + set_to_range(existing_set->init); + list_splice_sorted(&existing_set->init->expressions, + &init->expressions); + init_list_head(&existing_set->init->expressions); + } else { + existing_set->init = set_expr_alloc(&internal_location, set); + } +} + static void setelem_automerge(struct set_automerge_ctx *ctx) { struct expr *i, *next, *prev = NULL; @@ -222,18 +242,7 @@ int set_automerge(struct list_head *msgs, struct cmd *cmd, struct set *set, return 0; } - if (existing_set) { - if (existing_set->init) { - list_splice_init(&existing_set->init->expressions, - &init->expressions); - } else { - existing_set->init = set_expr_alloc(&internal_location, - set); - } - } - - set_to_range(init); - list_expr_sort(&init->expressions); + set_sort_splice(init, set); ctx.purge = set_expr_alloc(&internal_location, set); @@ -591,18 +600,7 @@ int set_overlap(struct list_head *msgs, struct set *set, struct expr *init) struct expr *i, *n, *clone; int err; - if (existing_set) { - if (existing_set->init) { - list_splice_init(&existing_set->init->expressions, - &init->expressions); - } else { - existing_set->init = set_expr_alloc(&internal_location, - set); - } - } - - set_to_range(init); - list_expr_sort(&init->expressions); + set_sort_splice(init, set); err = setelem_overlap(msgs, set, init); diff --git a/src/mergesort.c b/src/mergesort.c index 8e6aac5f..dca71422 100644 --- a/src/mergesort.c +++ b/src/mergesort.c @@ -70,7 +70,7 @@ static int expr_msort_cmp(const struct expr *e1, const struct expr *e2) return ret; } -static void list_splice_sorted(struct list_head *list, struct list_head *head) +void list_splice_sorted(struct list_head *list, struct list_head *head) { struct list_head *h = head->next; struct list_head *l = list->next; |