Mercurial > hg > nginx
comparison src/http/modules/ngx_http_log_module.c @ 3275:b344b68da8c5
optimize some cycles:
*) delete surplus variable;
*) on i386/amd64 "while (n) / n--" is smaller than "while (n--)",
because the platforms have no postfix operations
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 02 Nov 2009 17:12:09 +0000 |
parents | 204ea173234f |
children | bfe37ab335b5 |
comparison
equal
deleted
inserted
replaced
3274:95b0b0d7843f | 3275:b344b68da8c5 |
---|---|
648 | 648 |
649 | 649 |
650 static uintptr_t | 650 static uintptr_t |
651 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) | 651 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) |
652 { | 652 { |
653 ngx_uint_t i, n; | 653 ngx_uint_t n; |
654 static u_char hex[] = "0123456789ABCDEF"; | 654 static u_char hex[] = "0123456789ABCDEF"; |
655 | 655 |
656 static uint32_t escape[] = { | 656 static uint32_t escape[] = { |
657 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | 657 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
658 | 658 |
676 | 676 |
677 /* find the number of the characters to be escaped */ | 677 /* find the number of the characters to be escaped */ |
678 | 678 |
679 n = 0; | 679 n = 0; |
680 | 680 |
681 for (i = 0; i < size; i++) { | 681 while (size) { |
682 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | 682 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
683 n++; | 683 n++; |
684 } | 684 } |
685 src++; | 685 src++; |
686 size--; | |
686 } | 687 } |
687 | 688 |
688 return (uintptr_t) n; | 689 return (uintptr_t) n; |
689 } | 690 } |
690 | 691 |
691 for (i = 0; i < size; i++) { | 692 while (size) { |
692 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | 693 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
693 *dst++ = '\\'; | 694 *dst++ = '\\'; |
694 *dst++ = 'x'; | 695 *dst++ = 'x'; |
695 *dst++ = hex[*src >> 4]; | 696 *dst++ = hex[*src >> 4]; |
696 *dst++ = hex[*src & 0xf]; | 697 *dst++ = hex[*src & 0xf]; |
697 src++; | 698 src++; |
698 | 699 |
699 } else { | 700 } else { |
700 *dst++ = *src++; | 701 *dst++ = *src++; |
701 } | 702 } |
703 size--; | |
702 } | 704 } |
703 | 705 |
704 return (uintptr_t) dst; | 706 return (uintptr_t) dst; |
705 } | 707 } |
706 | 708 |