comparison src/http/ngx_http_core_module.c @ 2881:13b63d682228

light optimization of ngx_http_test_content_type()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 25 May 2009 09:00:35 +0000
parents 507fc5ac9839
children 512d164a8348
comparison
equal deleted inserted replaced
2880:ed741daa010a 2881:13b63d682228
1528 1528
1529 1529
1530 void * 1530 void *
1531 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash) 1531 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1532 { 1532 {
1533 u_char c, *p; 1533 u_char c, *lowcase;
1534 ngx_uint_t i, hash; 1534 size_t len;
1535 ngx_uint_t i, hash;
1535 1536
1536 if (r->headers_out.content_type.len == 0) { 1537 if (r->headers_out.content_type.len == 0) {
1537 return NULL; 1538 return NULL;
1538 } 1539 }
1539 1540
1541 len = r->headers_out.content_type_len;
1542
1540 if (r->headers_out.content_type_lowcase == NULL) { 1543 if (r->headers_out.content_type_lowcase == NULL) {
1541 1544
1542 p = ngx_pnalloc(r->pool, r->headers_out.content_type_len); 1545 lowcase = ngx_pnalloc(r->pool, len);
1543 1546 if (lowcase == NULL) {
1544 if (p == NULL) {
1545 return NULL; 1547 return NULL;
1546 } 1548 }
1547 1549
1548 r->headers_out.content_type_lowcase = p; 1550 r->headers_out.content_type_lowcase = lowcase;
1549 1551
1550 hash = 0; 1552 hash = 0;
1551 1553
1552 for (i = 0; i < r->headers_out.content_type_len; i++) { 1554 for (i = 0; i < len; i++) {
1553 c = ngx_tolower(r->headers_out.content_type.data[i]); 1555 c = ngx_tolower(r->headers_out.content_type.data[i]);
1554 hash = ngx_hash(hash, c); 1556 hash = ngx_hash(hash, c);
1555 *p++ = c; 1557 lowcase[i] = c;
1556 } 1558 }
1557 1559
1558 r->headers_out.content_type_hash = hash; 1560 r->headers_out.content_type_hash = hash;
1559 } 1561 }
1560 1562
1561 return ngx_hash_find(types_hash, 1563 return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
1562 r->headers_out.content_type_hash, 1564 r->headers_out.content_type_lowcase, len);
1563 r->headers_out.content_type_lowcase,
1564 r->headers_out.content_type_len);
1565 } 1565 }
1566 1566
1567 1567
1568 ngx_int_t 1568 ngx_int_t
1569 ngx_http_set_content_type(ngx_http_request_t *r) 1569 ngx_http_set_content_type(ngx_http_request_t *r)