]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
segtree: stop iteration on existing elements in case range is found
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 3 Oct 2018 14:19:47 +0000 (16:19 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 3 Oct 2018 14:23:05 +0000 (16:23 +0200)
No need to keep iterating once the range object has been allocated.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/segtree.c

index dc2554b72acf377ec448e7b2ba31789adb3f586e..dc457d6bc1b7df9b082536b30c28b77b739e387f 100644 (file)
@@ -661,16 +661,18 @@ static struct expr *get_set_interval_find(const struct table *table,
                        range_expr_value_low(low, i);
                        range_expr_value_high(high, i);
                        if (mpz_cmp(left->key->value, low) >= 0 &&
-                           mpz_cmp(right->key->value, high) <= 0)
+                           mpz_cmp(right->key->value, high) <= 0) {
                                range = range_expr_alloc(&internal_location,
                                                         expr_clone(left->key),
                                                         expr_clone(right->key));
+                               goto out;
+                       }
                        break;
                default:
                        break;
                }
        }
-
+out:
        mpz_clear(low);
        mpz_clear(high);
 
@@ -697,14 +699,14 @@ static struct expr *get_set_interval_end(const struct table *table,
                                range = range_expr_alloc(&internal_location,
                                                         expr_clone(left->key),
                                                         expr_clone(i->key->right));
-                               break;
+                               goto out;
                        }
                        break;
                default:
                        break;
                }
        }
-
+out:
        mpz_clear(low);
        mpz_clear(high);