Mercurial > hg > nginx
annotate src/core/ngx_crc32.h @ 1909:cbd321d1e1b3
C++ compatibility
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 03 Mar 2008 16:32:16 +0000 |
parents | d6afb8723155 |
children | d620f497c50f |
rev | line source |
---|---|
790 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #ifndef _NGX_CRC32_H_INCLUDED_ | |
8 #define _NGX_CRC32_H_INCLUDED_ | |
9 | |
10 | |
11 #include <ngx_config.h> | |
12 #include <ngx_core.h> | |
13 | |
14 | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
15 extern uint32_t *ngx_crc32_table_short; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
16 extern uint32_t ngx_crc32_table256[]; |
790 | 17 |
18 | |
19 static ngx_inline uint32_t | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
20 ngx_crc32_short(u_char *p, size_t len) |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
21 { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
22 u_char c; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
23 uint32_t crc; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
24 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
25 crc = 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
26 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
27 while (len--) { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
28 c = *p++; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
29 crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
30 crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
31 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
32 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
33 return crc ^ 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
34 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
35 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
36 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
37 static ngx_inline uint32_t |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
38 ngx_crc32_long(u_char *p, size_t len) |
790 | 39 { |
40 uint32_t crc; | |
41 | |
42 crc = 0xffffffff; | |
43 | |
44 while (len--) { | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
45 crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8); |
790 | 46 } |
47 | |
48 return crc ^ 0xffffffff; | |
49 } | |
50 | |
51 | |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
52 #define ngx_crc32_init(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
53 crc = 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
54 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
55 |
1697 | 56 static ngx_inline void |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
57 ngx_crc32_update(uint32_t *crc, u_char *p, size_t len) |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
58 { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
59 uint32_t c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
60 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
61 c = *crc; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
62 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
63 while (len--) { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
64 c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8); |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
65 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
66 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
67 *crc = c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
68 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
69 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
70 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
71 #define ngx_crc32_final(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
72 crc ^= 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
73 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
74 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
75 ngx_int_t ngx_crc32_table_init(void); |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
76 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
77 |
790 | 78 #endif /* _NGX_CRC32_H_INCLUDED_ */ |