]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
just recurse instead of being smart
authorAlan T. DeKok <aland@freeradius.org>
Sat, 16 Mar 2019 17:59:59 +0000 (13:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 16 Mar 2019 18:01:15 +0000 (14:01 -0400)
src/lib/util/trie.c

index 0f2a9af69fb0ac5b0cfa7b71af1f28e02f45c798..86af7b3d5d6eae537cc0ecfda91b68fe7ea9f35b 100644 (file)
@@ -1027,64 +1027,6 @@ static int fr_trie_node_insert(TALLOC_CTX *ctx, fr_trie_t *parent, fr_trie_t **t
 
        chunk = get_chunk(key, start_bit, node->bits);
 
-       /*
-        *      The current node exactly fits the key bits.
-        */
-       if ((start_bit + node->bits == end_bit)) {
-               fr_trie_user_t *user;
-
-               /*
-                *      No existing trie, create a brand new
-                *      user node from the key.
-                */
-               if (!node->trie[chunk]) {
-                       node->trie[chunk] = (fr_trie_t *) fr_trie_user_alloc(ctx, (fr_trie_t *) node, data);
-
-               add_new:
-                       node->used++;
-                       goto done_set;
-               }
-
-               /*
-                *      Can't insert user data on top of user
-                *      data.
-                */
-               if (node->trie[chunk]->type == FR_TRIE_USER) {
-                       fr_strerror_printf("already has a user node at %d\n", __LINE__);
-
-               fail:
-                       if (trie_to_free) fr_trie_free(trie_to_free);
-                       return -1;
-               }
-
-               /*
-                *      Otherwise there is already a trie at
-                *      the end of the key, so there's another
-                *      key which is longer.  Just create a
-                *      user node and wedge it into place.
-                */
-               user = fr_trie_user_alloc(ctx, (fr_trie_t *) node, data);
-               if (!user) {
-                       fr_strerror_printf("Failed user_alloc at %d\n", __LINE__);
-                       goto fail;
-               }
-
-               /*
-                *      Add the existing trie *after* the new
-                *      user data.  We do this by just
-                *      rearranging the trie.
-                */
-               user->trie = node->trie[chunk];
-               user->trie->parent = (fr_trie_t *) user;
-               node->trie[chunk] = (fr_trie_t *) user;
-               goto done_set;
-       }
-
-       /*
-        *      The current node is all within the key bits.
-        */
-       // assert ((start_bit + node->bits) < end_bit)
-
        /*
         *      No existing trie, create a brand new trie from
         *      the key.
@@ -1093,21 +1035,23 @@ static int fr_trie_node_insert(TALLOC_CTX *ctx, fr_trie_t *parent, fr_trie_t **t
                node->trie[chunk] = fr_trie_key_alloc(ctx, (fr_trie_t *) node, key, start_bit + node->bits, end_bit, data);
                if (!node->trie[chunk]) {
                        fr_strerror_printf("Failed key_alloc at %d\n", __LINE__);
-                       goto fail;
+                       if (trie_to_free) fr_trie_free(trie_to_free);
+                       return -1;
                }
-               goto add_new;
-       }
+               node->used++;
 
-       /*
-        *      Recurse in order to insert the key
-        *      into the current node.
-        */
-       if (fr_trie_key_insert(ctx, (fr_trie_t *) node, &node->trie[chunk], key, start_bit + node->bits, end_bit, data) < 0) {
-               MPRINT("Failed recursing at %d\n", __LINE__);
-               goto fail;
+       } else {
+               /*
+                *      Recurse in order to insert the key
+                *      into the current node.
+                */
+               if (fr_trie_key_insert(ctx, (fr_trie_t *) node, &node->trie[chunk], key, start_bit + node->bits, end_bit, data) < 0) {
+                       MPRINT("Failed recursing at %d\n", __LINE__);
+                       if (trie_to_free) fr_trie_free(trie_to_free);
+                       return -1;
+               }
        }
 
-done_set:
        if (trie_to_free) fr_trie_free(trie_to_free);
        *trie_p = (fr_trie_t *) node;
        node->parent = parent;