Răsfoiți Sursa

ncd: NCDInterpBlock: speed up statement lookups by using precomputed hashes

ambrop7 13 ani în urmă
părinte
comite
bad183475e
3 a modificat fișierele cu 4 adăugiri și 1 ștergeri
  1. 1 0
      ncd/NCDInterpBlock.c
  2. 1 0
      ncd/NCDInterpBlock.h
  3. 2 1
      ncd/NCDInterpBlock_hash.h

+ 1 - 0
ncd/NCDInterpBlock.c

@@ -176,6 +176,7 @@ int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block, NCDProcess *process
         struct NCDInterpBlock__stmt *e = &o->stmts[o->num_stmts];
         
         e->name = NCDStatement_Name(s);
+        e->name_hash = (!e->name ? 0 : badvpn_djb2_hash((const uint8_t *)e->name));
         e->cmdname = NCDStatement_RegCmdName(s);
         e->objnames = NULL;
         e->num_objnames = 0;

+ 1 - 0
ncd/NCDInterpBlock.h

@@ -41,6 +41,7 @@
 
 struct NCDInterpBlock__stmt {
     const char *name;
+    size_t name_hash;
     const char *cmdname;
     char *objnames;
     size_t num_objnames;

+ 2 - 1
ncd/NCDInterpBlock_hash.h

@@ -5,8 +5,9 @@
 #define CHASH_PARAM_ARG NCDInterpBlock__hasharg
 #define CHASH_PARAM_NULL ((int)-1)
 #define CHASH_PARAM_DEREF(arg, link) (&(arg)[(link)])
-#define CHASH_PARAM_ENTRYHASH(arg, entry) (badvpn_djb2_hash((const uint8_t *)(entry).ptr->name))
+#define CHASH_PARAM_ENTRYHASH(arg, entry) ((entry).ptr->name_hash)
 #define CHASH_PARAM_KEYHASH(arg, key) (badvpn_djb2_hash((const uint8_t *)(key)))
+#define CHASH_PARAM_ENTRYHASH_IS_CHEAP 1
 #define CHASH_PARAM_COMPARE_ENTRIES(arg, entry1, entry2) (!strcmp((entry1).ptr->name, (entry2).ptr->name))
 #define CHASH_PARAM_COMPARE_KEY_ENTRY(arg, key1, entry2) (!strcmp((key1), (entry2).ptr->name))
 #define CHASH_PARAM_ENTRY_NEXT hash_next