Mercurial > hg > nginx-ranges
comparison src/core/ngx_hash.c @ 635:e67b227c8dbb default tip
Merge with current.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:07:55 +0400 |
parents | 8246d8a2c2be |
children |
comparison
equal
deleted
inserted
replaced
578:f3a9e57d2e17 | 635:e67b227c8dbb |
---|---|
243 return NULL; | 243 return NULL; |
244 } | 244 } |
245 | 245 |
246 | 246 |
247 #define NGX_HASH_ELT_SIZE(name) \ | 247 #define NGX_HASH_ELT_SIZE(name) \ |
248 (sizeof(void *) + ngx_align((name)->key.len + 1, sizeof(void *))) | 248 (sizeof(void *) + ngx_align((name)->key.len + 2, sizeof(void *))) |
249 | 249 |
250 ngx_int_t | 250 ngx_int_t |
251 ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts) | 251 ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts) |
252 { | 252 { |
253 u_char *elts; | 253 u_char *elts; |
255 u_short *test; | 255 u_short *test; |
256 ngx_uint_t i, n, key, size, start, bucket_size; | 256 ngx_uint_t i, n, key, size, start, bucket_size; |
257 ngx_hash_elt_t *elt, **buckets; | 257 ngx_hash_elt_t *elt, **buckets; |
258 | 258 |
259 for (n = 0; n < nelts; n++) { | 259 for (n = 0; n < nelts; n++) { |
260 if (names[n].key.len >= 255) { | |
261 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, | |
262 "the \"%V\" value to hash is to long: %uz bytes, " | |
263 "the maximum length can be 255 bytes only", | |
264 &names[n].key, names[n].key.len); | |
265 return NGX_ERROR; | |
266 } | |
267 | |
268 if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *)) | 260 if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *)) |
269 { | 261 { |
270 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, | 262 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, |
271 "could not build the %s, you should " | 263 "could not build the %s, you should " |
272 "increase %s_bucket_size: %i", | 264 "increase %s_bucket_size: %i", |
404 | 396 |
405 key = names[n].key_hash % size; | 397 key = names[n].key_hash % size; |
406 elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]); | 398 elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]); |
407 | 399 |
408 elt->value = names[n].value; | 400 elt->value = names[n].value; |
409 elt->len = (u_char) names[n].key.len; | 401 elt->len = (u_short) names[n].key.len; |
410 | 402 |
411 ngx_strlow(elt->name, names[n].key.data, names[n].key.len); | 403 ngx_strlow(elt->name, names[n].key.data, names[n].key.len); |
412 | 404 |
413 test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); | 405 test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); |
414 } | 406 } |