Klaus Demo nginx / 6884183
allow hash key values more than 255 bytes, it does not actually increase mean hash element size, because due to aligning a byte after key is not used anyway in 3/4 cases on 32-bit platforms and in 7/8 cases on 64-bit platforms Igor Sysoev 12 years ago
2 changed file(s) with 3 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
244244
245245
246246 #define NGX_HASH_ELT_SIZE(name) \
247 (sizeof(void *) + ngx_align((name)->key.len + 1, sizeof(void *)))
247 (sizeof(void *) + ngx_align((name)->key.len + 2, sizeof(void *)))
248248
249249 ngx_int_t
250250 ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts)
256256 ngx_hash_elt_t *elt, **buckets;
257257
258258 for (n = 0; n < nelts; n++) {
259 if (names[n].key.len >= 255) {
260 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,
261 "the \"%V\" value to hash is to long: %uz bytes, "
262 "the maximum length can be 255 bytes only",
263 &names[n].key, names[n].key.len);
264 return NGX_ERROR;
265 }
266
267259 if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *))
268260 {
269261 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,
405397 elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]);
406398
407399 elt->value = names[n].value;
408 elt->len = (u_char) names[n].key.len;
400 elt->len = (u_short) names[n].key.len;
409401
410402 ngx_strlow(elt->name, names[n].key.data, names[n].key.len);
411403
1313
1414 typedef struct {
1515 void *value;
16 u_char len;
16 u_short len;
1717 u_char name[1];
1818 } ngx_hash_elt_t;
1919