Commit acacc66c authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd: using struct initializer idiom to set a const field

	(trying to hint the compiler to use constant bit mask in hash)
parent e843c230
...@@ -105,7 +105,7 @@ VTAILQ_HEAD(insert_head_s, hashentry_s); ...@@ -105,7 +105,7 @@ VTAILQ_HEAD(insert_head_s, hashentry_s);
struct hashtable_s { struct hashtable_s {
unsigned magic; unsigned magic;
#define HASHTABLE_MAGIC 0x89ea1d00 #define HASHTABLE_MAGIC 0x89ea1d00
unsigned len; const unsigned len;
hashentry *entry; hashentry *entry;
struct insert_head_s insert_head; struct insert_head_s insert_head;
...@@ -382,17 +382,22 @@ hash_init(void) ...@@ -382,17 +382,22 @@ hash_init(void)
if (entryptr == NULL) if (entryptr == NULL)
return(errno); return(errno);
memset(&htbl, 0, sizeof(hashtable)); /* Struct initializer makes it possible to set len as a const field;
htbl.magic = HASHTABLE_MAGIC; trying to hint the compiler to use a constant when translating the
htbl.len = entries; INDEX() code.
htbl.entry = entryptr; */
hashtable init_tbl
= { .magic = HASHTABLE_MAGIC, .len = entries, .entry = entryptr,
.max_probes = config.hash_max_probes, .ttl = config.hash_ttl,
.mlt = config.hash_mlt, .seen = 0, .drop_reqstart = 0,
.drop_vcl_log = 0, .drop_reqend = 0, .expired = 0,
.evacuated = 0, .open = 0, .collisions = 0, .insert_probes = 0,
.find_probes = 0, .fail = 0, .occ_hi = 0, .occ_hi_this = 0
};
memcpy(&htbl, &init_tbl, sizeof(hashtable));
VTAILQ_INIT(&htbl.insert_head); VTAILQ_INIT(&htbl.insert_head);
htbl.max_probes = config.hash_max_probes;
htbl.ttl = config.hash_ttl;
htbl.mlt = config.hash_mlt;
/* entries init */ /* entries init */
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
htbl.entry[i].magic = HASH_MAGIC; htbl.entry[i].magic = HASH_MAGIC;
......
...@@ -40,9 +40,6 @@ ...@@ -40,9 +40,6 @@
#include "vqueue.h" #include "vqueue.h"
#include "varnishapi.h" #include "varnishapi.h"
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) < (y) ? (y) : (x))
/* assert.c */ /* assert.c */
void ASRT_Fail(const char *func, const char *file, int line, const char *cond, void ASRT_Fail(const char *func, const char *file, int line, const char *cond,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment