]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: stuff xrefs into a tree for lookup
authorDavid Lamparter <equinox@diac24.net>
Wed, 24 Feb 2021 10:57:15 +0000 (11:57 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 10 Nov 2021 09:39:17 +0000 (10:39 +0100)
... so we can actually access by UID without searching the entire list.

Signed-off-by: David Lamparter <equinox@diac24.net>
lib/xref.c
lib/xref.h

index a41f91a2289f322cd5d3656acb63c75054fce1ba..0d3549d0620d5c9d3d2d156234ee3ca91ddbba84 100644 (file)
@@ -35,6 +35,8 @@
 struct xref_block *xref_blocks;
 static struct xref_block **xref_block_last = &xref_blocks;
 
+struct xrefdata_uid_head xrefdata_uid = INIT_RBTREE_UNIQ(xrefdata_uid);
+
 static void base32(uint8_t **inpos, int *bitpos,
                   char *out, size_t n_chars)
 {
@@ -109,6 +111,8 @@ static void xref_add_one(const struct xref *xref)
        base32(&h, &bitpos, &xrefdata->uid[0], 5);
        xrefdata->uid[5] = '-';
        base32(&h, &bitpos, &xrefdata->uid[6], 5);
+
+       xrefdata_uid_add(&xrefdata_uid, xrefdata);
 }
 
 void xref_gcc_workaround(const struct xref *xref)
index 6cff1a376999a41137de8755cc07f8b4d49967ae..0e3f00f6907f12eea6a9499b6a0ab1232f4c548b 100644 (file)
@@ -22,6 +22,7 @@
 #include <limits.h>
 #include <errno.h>
 #include "compiler.h"
+#include "typesafe.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -63,6 +64,8 @@ struct xref {
        /* type-specific bits appended by embedding this struct */
 };
 
+PREDECL_RBTREE_UNIQ(xrefdata_uid);
+
 struct xrefdata {
        /* pointer back to the const part;  this will be initialized at
         * program startup by xref_block_add().  (Creating structs with
@@ -88,8 +91,18 @@ struct xrefdata {
        uint32_t hashu32[2];
 
        /* -- 32 bytes (on 64bit) -- */
+       struct xrefdata_uid_item xui;
 };
 
+static inline int xrefdata_uid_cmp(const struct xrefdata *a,
+                                  const struct xrefdata *b)
+{
+       return strcmp(a->uid, b->uid);
+}
+
+DECLARE_RBTREE_UNIQ(xrefdata_uid, struct xrefdata, xui, xrefdata_uid_cmp);
+extern struct xrefdata_uid_head xrefdata_uid;
+
 /* linker "magic" is used to create an array of pointers to struct xref.
  * the result is a contiguous block of pointers, each pointing to an xref
  * somewhere in the code.  The linker gives us start and end pointers, we