Mercurial > hg > nginx-vendor-0-7
comparison src/core/ngx_hash.c @ 198:e6da4931e0e0 NGINX_0_3_46
nginx 0.3.46
*) Feature: the "proxy_hide_header", "proxy_pass_header",
"fastcgi_hide_header", and "fastcgi_pass_header" directives.
*) Change: the "proxy_pass_x_powered_by", "fastcgi_x_powered_by", and
"proxy_pass_server" directives were canceled.
*) Feature: the "X-Accel-Buffering" response header line is supported
in proxy mode.
*) Bugfix: the reconfiguration bug and memory leaks in the
ngx_http_perl_module.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 11 May 2006 00:00:00 +0400 |
parents | 4cd3e70c4d60 |
children | ff906029dd40 |
comparison
equal
deleted
inserted
replaced
197:93658b91fad2 | 198:e6da4931e0e0 |
---|---|
523 return key; | 523 return key; |
524 } | 524 } |
525 | 525 |
526 | 526 |
527 ngx_int_t | 527 ngx_int_t |
528 ngx_hash0_init(ngx_hash0_t *hash, ngx_pool_t *pool, void *names, | |
529 ngx_uint_t nelts) | |
530 { | |
531 u_char *p; | |
532 ngx_str_t *name, *bucket; | |
533 ngx_uint_t i, n, key, size, best, *test, buckets, min_buckets; | |
534 | |
535 if (nelts == 0) { | |
536 for (name = (ngx_str_t *) names; | |
537 name->len; | |
538 name = (ngx_str_t *) ((char *) name + hash->bucket_size)) | |
539 { | |
540 nelts++; | |
541 } | |
542 } | |
543 | |
544 test = ngx_alloc(hash->max_size * sizeof(ngx_uint_t), pool->log); | |
545 if (test == NULL) { | |
546 return NGX_ERROR; | |
547 } | |
548 | |
549 min_buckets = hash->bucket_limit + 1; | |
550 | |
551 #if (NGX_SUPPRESS_WARN) | |
552 best = 0; | |
553 #endif | |
554 | |
555 for (size = 1; size < hash->max_size; size++) { | |
556 | |
557 buckets = 0; | |
558 | |
559 for (i = 0; i < size; i++) { | |
560 test[i] = 0; | |
561 } | |
562 | |
563 for (n = 0, name = (ngx_str_t *) names; | |
564 n < nelts; | |
565 n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) | |
566 { | |
567 if (name->data == NULL) { | |
568 continue; | |
569 } | |
570 | |
571 key = 0; | |
572 | |
573 for (i = 0; i < name->len; i++) { | |
574 key += ngx_tolower(name->data[i]); | |
575 } | |
576 | |
577 key %= size; | |
578 | |
579 if (test[key] == hash->bucket_limit) { | |
580 break; | |
581 } | |
582 | |
583 test[key]++; | |
584 | |
585 if (buckets < test[key]) { | |
586 buckets = test[key]; | |
587 } | |
588 } | |
589 | |
590 if (n == nelts) { | |
591 if (min_buckets > buckets) { | |
592 min_buckets = buckets; | |
593 best = size; | |
594 } | |
595 | |
596 if (hash->bucket_limit == 1) { | |
597 break; | |
598 } | |
599 } | |
600 } | |
601 | |
602 if (min_buckets == hash->bucket_limit + 1) { | |
603 ngx_log_error(NGX_LOG_EMERG, pool->log, 0, | |
604 "could not build the %s hash, you should increase " | |
605 "either %s_size: %i or %s_bucket_limit: %i", | |
606 hash->name, hash->name, hash->max_size, | |
607 hash->name, hash->bucket_limit); | |
608 ngx_free(test); | |
609 return NGX_ERROR; | |
610 } | |
611 | |
612 hash->buckets = ngx_pcalloc(pool, best * hash->bucket_size); | |
613 if (hash->buckets == NULL) { | |
614 ngx_free(test); | |
615 return NGX_ERROR; | |
616 } | |
617 | |
618 if (hash->bucket_limit != 1) { | |
619 | |
620 for (i = 0; i < best; i++) { | |
621 test[i] = 0; | |
622 } | |
623 | |
624 for (n = 0, name = (ngx_str_t *) names; | |
625 n < nelts; | |
626 n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) | |
627 { | |
628 if (name->data == NULL) { | |
629 continue; | |
630 } | |
631 | |
632 key = 0; | |
633 | |
634 for (i = 0; i < name->len; i++) { | |
635 key += ngx_tolower(name->data[i]); | |
636 } | |
637 | |
638 key %= best; | |
639 | |
640 test[key]++; | |
641 } | |
642 | |
643 for (i = 0; i < best; i++) { | |
644 if (test[i] == 0) { | |
645 continue; | |
646 } | |
647 | |
648 bucket = ngx_palloc(pool, test[i] * hash->bucket_size); | |
649 if (bucket == NULL) { | |
650 ngx_free(test); | |
651 return NGX_ERROR; | |
652 } | |
653 | |
654 hash->buckets[i] = bucket; | |
655 bucket->len = 0; | |
656 } | |
657 } | |
658 | |
659 for (n = 0, name = (ngx_str_t *) names; | |
660 n < nelts; | |
661 n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) | |
662 { | |
663 if (name->data == NULL) { | |
664 continue; | |
665 } | |
666 | |
667 key = 0; | |
668 | |
669 for (i = 0; i < name->len; i++) { | |
670 key += ngx_tolower(name->data[i]); | |
671 } | |
672 | |
673 key %= best; | |
674 | |
675 if (hash->bucket_limit == 1) { | |
676 p = (u_char *) hash->buckets + key * hash->bucket_size; | |
677 ngx_memcpy(p, name, hash->bucket_size); | |
678 continue; | |
679 } | |
680 | |
681 for (bucket = hash->buckets[key]; | |
682 bucket->len; | |
683 bucket = (ngx_str_t *) ((char *) bucket + hash->bucket_size)) | |
684 { | |
685 bucket->len &= 0x7fffffff; | |
686 } | |
687 | |
688 ngx_memcpy(bucket, name, hash->bucket_size); | |
689 bucket->len |= 0x80000000; | |
690 } | |
691 | |
692 ngx_free(test); | |
693 | |
694 hash->hash_size = best; | |
695 hash->min_buckets = min_buckets; | |
696 | |
697 return NGX_OK; | |
698 } | |
699 | |
700 | |
701 ngx_int_t | |
702 ngx_hash_keys_array_init(ngx_hash_keys_arrays_t *ha, ngx_uint_t type) | 528 ngx_hash_keys_array_init(ngx_hash_keys_arrays_t *ha, ngx_uint_t type) |
703 { | 529 { |
704 ngx_uint_t asize; | 530 ngx_uint_t asize; |
705 | 531 |
706 if (type == NGX_HASH_SMALL) { | 532 if (type == NGX_HASH_SMALL) { |