]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
segtree: Use expr_clone in get_set_interval_*()
authorPhil Sutter <phil@nwl.cc>
Thu, 30 Apr 2020 11:45:40 +0000 (13:45 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 4 May 2020 14:21:16 +0000 (16:21 +0200)
Both functions perform interval set lookups with either start and end or
only start values as input. Interestingly, in practice they either see
values which are not contained or which match an existing range exactly.

Make use of the above and just return a clone of the matching entry
instead of creating a new one based on input data.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/segtree.c

index 002ee41a16db09ce526148c10019bca0cc4b38a6..f81a66e185990a69da3ab6caea055d634f81cd07 100644 (file)
@@ -708,9 +708,7 @@ static struct expr *get_set_interval_find(const struct table *table,
                        range_expr_value_high(high, i);
                        if (mpz_cmp(left->key->value, low) >= 0 &&
                            mpz_cmp(right->key->value, high) <= 0) {
-                               range = range_expr_alloc(&internal_location,
-                                                        expr_clone(left->key),
-                                                        expr_clone(right->key));
+                               range = expr_clone(i->key);
                                goto out;
                        }
                        break;
@@ -742,9 +740,7 @@ static struct expr *get_set_interval_end(const struct table *table,
                case EXPR_RANGE:
                        range_expr_value_low(low, i);
                        if (mpz_cmp(low, left->key->value) == 0) {
-                               range = range_expr_alloc(&internal_location,
-                                                        expr_clone(left->key),
-                                                        expr_clone(i->key->right));
+                               range = expr_clone(i->key);
                                goto out;
                        }
                        break;