the thing builds, again

pull/4/head
Adrian Perez 2007-09-04 19:29:53 +02:00
parent 97c2710a12
commit afcb883c7a
3 changed files with 68 additions and 137 deletions

View File

@ -1,20 +1,7 @@
/* /*
* include+cache.c * inliner.c
* Copyright © 2007 Adrian Perez <adrianperez@udc.es> * Copyright © 2007 Adrian Perez <adrianperez@udc.es>
* *
* Distributed under terms of the MIT license. * Distributed under terms of the MIT license.
*/ */
#include "ngx_http_fancyindex_module.h"
#include <ngx_rbtree.h>
static int s_inliner_init_done = 0;
int
nfi_inliner_init(void)
{
if (s_inliner_init_done) return 1;
}

View File

@ -23,8 +23,8 @@
#define NGX_DICT_HASHN(_k, _s, _n) (ngx_dict_hashnstr(_k, _n) % ((_s) - 1)) #define NGX_DICT_HASHN(_k, _s, _n) (ngx_dict_hashnstr(_k, _n) % ((_s) - 1))
#endif /* !NGX_DICT_HASHN */ #endif /* !NGX_DICT_HASHN */
#ifndef NFI_DICT_KEY_EQ #ifndef NGX_DICT_KEY_EQ
#define NFI_DICT_KEY_EQ(_a, _b) (ngx_dict_streq((_a), (_b))) #define NGX_DICT_KEY_EQ(_a, _b) (ngx_dict_streq((_a), (_b)))
#endif /* !NGX_DICT_KEY_EQ */ #endif /* !NGX_DICT_KEY_EQ */
#ifndef NGX_DICT_KEY_EQN #ifndef NGX_DICT_KEY_EQN
@ -34,32 +34,6 @@
#include "ngx_dict.h" #include "ngx_dict.h"
typedef struct ngx_dict_node ngx_dict_node_t;
/*
* XXX Never, NEVER, change the layout of this struct. If XXX
* XXX you want to add new fields, ADD FIELDS AT THE END. XXX
*/
struct ngx_dict_node
{
void *val;
ngx_str_t key;
ngx_dict_node_t *next;
ngx_dict_node_t *nextNode;
ngx_dict_node_t *prevNode;
};
struct ngx_dict
{
ngx_dict_node_t **nodes;
ngx_dict_node_t *first;
unsigned count;
unsigned size;
};
static ngx_slab_pool_t s_node_slab; static ngx_slab_pool_t s_node_slab;
static ngx_slab_pool_t s_strs_slab; static ngx_slab_pool_t s_strs_slab;
@ -122,8 +96,9 @@ int
ngx_dict_init(ngx_pool_t *pool, ngx_dict_t *d) ngx_dict_init(ngx_pool_t *pool, ngx_dict_t *d)
{ {
d->size = NGX_DICT_DEFAULT_SIZE; d->size = NGX_DICT_DEFAULT_SIZE;
/* TODO: Allocate this one... from where? */ /* TODO: Allocate this one... from where?
d->nodes = w_alloc(w_dict_node_t*, d->size); d->nodes = w_alloc(w_dict_node_t*, d->size);
*/
return 1; return 1;
} }
@ -139,13 +114,6 @@ ngx_dict_free(ngx_dict_t *d)
} }
unsigned
ngx_dict_count(const ngx_dict_t *d)
{
return d->count;
}
void void
ngx_dict_clear(ngx_dict_t *d) ngx_dict_clear(ngx_dict_t *d)
{ {
@ -154,13 +122,6 @@ ngx_dict_clear(ngx_dict_t *d)
} }
void*
ngx_dict_get(const ngx_dict_t *d, const ngx_str_t *key)
{
return ngx_dict_getn(d, key, key->len);
}
void* void*
ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t len) ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t len)
{ {
@ -171,14 +132,14 @@ ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t len)
node = d->nodes[hval]; node = d->nodes[hval];
if (node) { if (node) {
if (NGX_DICT_KEY_EQN(node->key, key, len)) { if (NGX_DICT_KEY_EQN(&node->key, key, len)) {
return node->val; return node->val;
} }
else { else {
ngx_dict_node_t *lastNode = node; ngx_dict_node_t *lastNode = node;
node = node->next; node = node->next;
while (node) { while (node) {
if (NGX_DICT_KEY_EQN(node->key, key, len)) { if (NGX_DICT_KEY_EQN(&node->key, key, len)) {
lastNode->next = node->next; lastNode->next = node->next;
node->next = d->nodes[hval]; node->next = d->nodes[hval];
d->nodes[hval] = node; d->nodes[hval] = node;
@ -194,7 +155,7 @@ ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t len)
static inline void static inline void
_ngx_dict_rehash(w_dict_t *d) _ngx_dict_rehash(ngx_dict_t *d)
{ {
ngx_dict_node_t *node = d->first; ngx_dict_node_t *node = d->first;
@ -210,7 +171,7 @@ _ngx_dict_rehash(w_dict_t *d)
memset(d->nodes, 0x00, d->size * sizeof(ngx_dict_node_t*)); memset(d->nodes, 0x00, d->size * sizeof(ngx_dict_node_t*));
for (node = d->first; node; node = node->nextNode) { for (node = d->first; node; node = node->nextNode) {
unsigned hval = NGX_DICT_HASH(node->key, d->size); unsigned hval = NGX_DICT_HASH(&node->key, d->size);
ngx_dict_node_t *n = d->nodes[hval]; ngx_dict_node_t *n = d->nodes[hval];
if (!n) d->nodes[hval] = node; if (!n) d->nodes[hval] = node;
else { else {
@ -225,12 +186,6 @@ _ngx_dict_rehash(w_dict_t *d)
} }
void
ngx_dict_set(ngx_dict_t *d, const char *key, void *val)
{
ngx_dict_setn(d, key, key->len, val);
}
void void
ngx_dict_setn(ngx_dict_t *d, const ngx_str_t *key, size_t len, void *val) ngx_dict_setn(ngx_dict_t *d, const ngx_str_t *key, size_t len, void *val)
@ -242,7 +197,7 @@ ngx_dict_setn(ngx_dict_t *d, const ngx_str_t *key, size_t len, void *val)
node = d->nodes[hval]; node = d->nodes[hval];
while (node) { while (node) {
if (NGX_DICT_KEY_EQN(node->key, key, len)) { if (NGX_DICT_KEY_EQN(&node->key, key, len)) {
node->val = val; node->val = val;
return; return;
} }
@ -274,7 +229,7 @@ ngx_dict_del(ngx_dict_t *d, const ngx_str_t *key)
hval = NGX_DICT_HASH(key, d->size); hval = NGX_DICT_HASH(key, d->size);
for (node = d->nodes[hval]; node; node = node->next) { for (node = d->nodes[hval]; node; node = node->next) {
if (NGX_DICT_KEY_EQ(node->key, key)) { if (NGX_DICT_KEY_EQ(&node->key, key)) {
ngx_dict_node_t *prevNode = node->prevNode; ngx_dict_node_t *prevNode = node->prevNode;
ngx_dict_node_t *nextNode = node->nextNode; ngx_dict_node_t *nextNode = node->nextNode;
@ -285,7 +240,7 @@ ngx_dict_del(ngx_dict_t *d, const ngx_str_t *key)
if (lastNode) lastNode->next = node->next; if (lastNode) lastNode->next = node->next;
else d->nodes[hval] = node->next; else d->nodes[hval] = node->next;
_w_dict_node_free(node); _ngx_dict_node_free(node);
d->count--; d->count--;
return; return;
} }
@ -293,58 +248,32 @@ ngx_dict_del(ngx_dict_t *d, const ngx_str_t *key)
} }
ngx_dict_iterator_t void
ngx_dict_first(const ngx_dict_t *d) ngx_dict_traverse_nodes(const ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx)
{ {
return (ngx_dict_iterator_t) d->first; ngx_dict_node_t *n;
}
for (n = ngx_dict_first_node(d); n != NULL; n = ngx_dict_next_node(n))
ngx_dict_iterator_t (*f)(n, ctx);
ngx_dict_next(const ngx_dict_t *d, ngx_dict_iterator_t i)
{
ngx_dict_node_t *node = (ngx_dict_node_t*) i;
(void) d; /* Avoid compiler warnings. */
return (ngx_dict_iterator_t) node->nextNode;
}
const ngx_str_t const*
ngx_dict_iterator_get_key(ngx_dict_iterator_t i)
{
ngx_dict_node_t *node = (ngx_dict_node_t*) i;
return node->key;
} }
void void
ngx_dict_traverse(ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx) ngx_dict_traverse_keys(const ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx)
{ {
ngx_dict_iterator_t i; ngx_dict_node_t *n;
for (i = ngx_dict_first(d); i != NULL; i = ngx_dict_next(d, i)) for (n = ngx_dict_first_node(d); n != NULL; n = ngx_dict_next_node(n))
*i = (*f)(*i, ctx); (*f)(&n->key, ctx);
} }
void void
ngx_dict_traverse_keys(ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx) ngx_dict_traverse_values(const ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx)
{ {
ngx_dict_item_t *i; ngx_dict_node_t *n;
for (i = ngx_dict_item_first(d); i != NULL; i = ngx_dict_item_next(d, i)) for (n = ngx_dict_first_node(d); n != NULL; n = ngx_dict_next_node(n))
(*f)((void*) i->key, ctx); (*f)(n->val, ctx);
}
void
ngx_dict_traverse_values(ngx_dict_t *d, ngx_dict_traverse_fun_t f, void *ctx)
{
ngx_dict_item_t *i;
for (i = ngx_dict_item_first(d); i != NULL; i = ngx_dict_item_next(d, i))
i->val = (*f)(i->val, ctx);
} }

View File

@ -6,24 +6,26 @@
#ifndef __ngx_dict_h__ #ifndef __ngx_dict_h__
#define __ngx_dict_h__ 1 #define __ngx_dict_h__ 1
#include <ngx_config.h>
#include <ngx_core.h> #include <ngx_core.h>
/* /*
* Declarations for inline stuff (implemented below) * Declarations for inline stuff (implemented below)
*/ */
static inline int static inline int
ngx_dict_streq(const ngx_str_t *a, const ngx_str_t *b); ngx_dict_streq(const ngx_str_t const* a, const ngx_str_t const* b);
static inline int static inline int
ngx_dict_strneq(const ngx_str_t *a, const ngx_str_t, register size_t len); ngx_dict_strneq(const ngx_str_t const* a, const ngx_str_t const* b,
register size_t len);
static inline unsigned static inline unsigned
ngx_dict__strhash(const ngx_str_t *s); ngx_dict_strhash(const ngx_str_t *s);
static inline unsigned static inline unsigned
ngx_dict_strnhash(const ngx_str_t *s, register size_t len); ngx_dict_strnhash(const ngx_str_t *s, register size_t len);
typedef struct ngx_dict ngx_dict_t; typedef struct ngx_dict ngx_dict_t;
typedef void** ngx_dict_iterator_t;
typedef void (*ngx_dict_traverse_fun_t)(void *data, void *context);
int ngx_dict_init(ngx_pool_t *pool, ngx_dict_t *d); int ngx_dict_init(ngx_pool_t *pool, ngx_dict_t *d);
@ -35,13 +37,16 @@ size_t ngx_dict_count(const ngx_dict_t *d);
void* ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t keylen); void* ngx_dict_getn(const ngx_dict_t *d, const ngx_str_t *key, size_t keylen);
void ngx_dict_setn(ngx_dict_t *d, const ngx_str_t *key, size_t keylen, void *data); void ngx_dict_setn(ngx_dict_t *d, const ngx_str_t *key, size_t keylen, void *data);
void ngx_dict_del(ngx_dict_t *d, const ngx_str_t *key); #define ngx_dict_get(_d, _s) \
void ngx_dict_set(ngx_dict_t *d, const ngx_str_t *key, void *data); ngx_dict_getn((_d), (_s), (_s)->len)
void* ngx_dict_get(const ngx_dict_t *d, const ngx_str_t *key);
#define ngx_dict_set(_d, _s, _v) \
ngx_dict_setn((_d), (_s), (_s)->len, (_v))
void ngx_dict_del(ngx_dict_t *d, const ngx_str_t *key);
void ngx_dict_update(ngx_dict_t *d, const ngx_dict_t *o); void ngx_dict_update(ngx_dict_t *d, const ngx_dict_t *o);
void ngx_dict_traverse(const ngx_dict_t *d, void ngx_dict_traverse_nodes(const ngx_dict_t *d,
ngx_dict_traverse_fun_t f, void *ctx); ngx_dict_traverse_fun_t f, void *ctx);
void ngx_dict_traverse_keys(const ngx_dict_t *d, void ngx_dict_traverse_keys(const ngx_dict_t *d,
@ -50,30 +55,40 @@ void ngx_dict_traverse_keys(const ngx_dict_t *d,
void ngx_dict_traverse_values(const ngx_dict_t *d, void ngx_dict_traverse_values(const ngx_dict_t *d,
ngx_dict_traverse_fun_t f, void *ctx); ngx_dict_traverse_fun_t f, void *ctx);
ngx_dict_iterator_t ngx_dict_first(const ngx_dict_t *d);
ngx_dict_iterator_t ngx_dict_next(const ngx_dict_t *d, ngx_dict_iterator_t i);
const char ngx_str_t* ngx_dict_iterator_get_key(ngx_iterator_t i);
/* /*
* XXX: Never, NEVER change the layout of this structure. This **MUST** * This is the layout of a dictionary node. Do not move "val" out of the
* follow w_dict_node_t defined in wopt.c. * first place, or the iterator trick won't work anymore.
* XXX: They key is totally unmodifiable, as it is insane to change it while
* traversing the dictionary.
*/ */
struct ngx_dict_item typedef struct ngx_dict_node ngx_dict_node_t;
struct ngx_dict_node
{ {
void *val; void *val;
const ngx_str_t const* key; ngx_str_t key;
ngx_dict_node_t *next;
ngx_dict_node_t *nextNode;
ngx_dict_node_t *prevNode;
}; };
typedef struct ngx_dict_item ngx_dict_item_t;
#define ngx_dict_item_first(_d) \ struct ngx_dict
((ngx_dict_item_t*) ngx_dict_first(_d)) {
ngx_dict_node_t **nodes;
ngx_dict_node_t *first;
unsigned count;
unsigned size;
};
#define ngx_dict_item_next(_d, _i) \
((ngx_dict_item_t*) ngx_dict_next((_d), (ngx_iterator_t)(_i))) #define ngx_dict_first_node(_d) \
((_d)->first)
#define ngx_dict_next_node(_n) \
((_n)->nextNode)
#define ngx_dict_count(_d) \
((_d)->count)
/* /*
@ -81,7 +96,7 @@ typedef struct ngx_dict_item ngx_dict_item_t;
*/ */
static inline int static inline int
ngx_dict_streq(const ngx_str_t *a, const ngx_str_t *b) ngx_dict_streq(const ngx_str_t const* a, const ngx_str_t const* b)
{ {
register unsigned len; register unsigned len;
u_char *sa, *sb; u_char *sa, *sb;
@ -96,7 +111,7 @@ ngx_dict_streq(const ngx_str_t *a, const ngx_str_t *b)
static inline int static inline int
ngx_dict_strneq(const ngx_str_t *a, const ngx_str_t, register unsigned len) ngx_dict_strneq(const ngx_str_t const* a, const ngx_str_t const* b, register size_t len)
{ {
u_char *sa, *sb; u_char *sa, *sb;
@ -126,7 +141,7 @@ ngx_dict_hashstr(const ngx_str_t *s)
static inline unsigned static inline unsigned
nfi_dict_hashnstr(const ngx_str_t *s, register unsigned len) ngx_dict_hashnstr(const ngx_str_t *s, register unsigned len)
{ {
register unsigned ret = 0; register unsigned ret = 0;
register unsigned ctr = 0; register unsigned ctr = 0;