Mercurial > hg > nginx
comparison src/core/ngx_crc32.h @ 793:8d39da951bbd
split ngx_crc32() to short and long version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 19 Oct 2006 09:57:49 +0000 |
parents | f9a971440614 |
children | 45df22906c12 |
comparison
equal
deleted
inserted
replaced
792:99858705b03f | 793:8d39da951bbd |
---|---|
10 | 10 |
11 #include <ngx_config.h> | 11 #include <ngx_config.h> |
12 #include <ngx_core.h> | 12 #include <ngx_core.h> |
13 | 13 |
14 | 14 |
15 extern uint32_t ngx_crc32_table[]; | 15 extern uint32_t *ngx_crc32_table_short; |
16 extern uint32_t ngx_crc32_table256[]; | |
16 | 17 |
17 | 18 |
18 static ngx_inline uint32_t | 19 static ngx_inline uint32_t |
19 ngx_crc32(u_char *p, size_t len) | 20 ngx_crc32_short(u_char *p, size_t len) |
21 { | |
22 u_char c; | |
23 uint32_t crc; | |
24 | |
25 crc = 0xffffffff; | |
26 | |
27 while (len--) { | |
28 c = *p++; | |
29 crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4); | |
30 crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4); | |
31 } | |
32 | |
33 return crc ^ 0xffffffff; | |
34 } | |
35 | |
36 | |
37 static ngx_inline uint32_t | |
38 ngx_crc32_long(u_char *p, size_t len) | |
20 { | 39 { |
21 uint32_t crc; | 40 uint32_t crc; |
22 | 41 |
23 crc = 0xffffffff; | 42 crc = 0xffffffff; |
24 | 43 |
25 while (len--) { | 44 while (len--) { |
26 crc = ngx_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); | 45 crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8); |
27 } | 46 } |
28 | 47 |
29 return crc ^ 0xffffffff; | 48 return crc ^ 0xffffffff; |
30 } | 49 } |
31 | 50 |
32 | 51 |
52 ngx_int_t ngx_crc32_init(ngx_pool_t *pool); | |
53 | |
54 | |
33 #endif /* _NGX_CRC32_H_INCLUDED_ */ | 55 #endif /* _NGX_CRC32_H_INCLUDED_ */ |