comparison src/core/ngx_hash.c @ 144:e1c6ac408b68 NGINX_0_3_19

nginx 0.3.19 *) Feature: the "path" and "alias" directives support the variables. *) Change: now the "valid_referers" directive again checks the URI part. *) Bugfix: in SSI handling.
author Igor Sysoev <http://sysoev.ru>
date Wed, 28 Dec 2005 00:00:00 +0300
parents 84910468f6de
children 36af50a5582d
comparison
equal deleted inserted replaced
143:c2fa0caa07f2 144:e1c6ac408b68
127 return hwc->value; 127 return hwc->value;
128 } 128 }
129 129
130 130
131 #define NGX_HASH_ELT_SIZE(name) \ 131 #define NGX_HASH_ELT_SIZE(name) \
132 sizeof(void *) + ngx_align((name)->key.len + 1, sizeof(void *)) 132 (sizeof(void *) + ngx_align((name)->key.len + 1, sizeof(void *)))
133 133
134 ngx_int_t 134 ngx_int_t
135 ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts) 135 ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts)
136 { 136 {
137 u_char *elts; 137 u_char *elts;
138 size_t *test, len; 138 size_t len;
139 u_short *test;
139 ngx_uint_t i, n, key, size, start, bucket_size; 140 ngx_uint_t i, n, key, size, start, bucket_size;
140 ngx_hash_elt_t *elt, **buckets; 141 ngx_hash_elt_t *elt, **buckets;
141 142
142 for (n = 0; n < nelts; n++) { 143 for (n = 0; n < nelts; n++) {
143 if (names[n].key.len >= 255) { 144 if (names[n].key.len >= 255) {
149 } 150 }
150 151
151 if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *)) 152 if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *))
152 { 153 {
153 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, 154 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,
154 "could not build the %s hash, you should " 155 "could not build the %s, you should "
155 "increase %s_bucket_size: %i", 156 "increase %s_bucket_size: %i",
156 hinit->name, hinit->name, hinit->bucket_size); 157 hinit->name, hinit->name, hinit->bucket_size);
157 return NGX_ERROR; 158 return NGX_ERROR;
158 } 159 }
159 } 160 }
160 161
161 test = ngx_alloc(hinit->max_size * sizeof(size_t), hinit->pool->log); 162 test = ngx_alloc(hinit->max_size * sizeof(u_short), hinit->pool->log);
162 if (test == NULL) { 163 if (test == NULL) {
163 return NGX_ERROR; 164 return NGX_ERROR;
164 } 165 }
165 166
166 start = nelts / (ngx_cacheline_size / (2 * sizeof(void *)) - 1); 167 start = nelts / (ngx_cacheline_size / (2 * sizeof(void *)) - 1);
168 169
169 bucket_size = hinit->bucket_size - sizeof(void *); 170 bucket_size = hinit->bucket_size - sizeof(void *);
170 171
171 for (size = start; size < hinit->max_size; size++) { 172 for (size = start; size < hinit->max_size; size++) {
172 173
173 ngx_memzero(test, size * sizeof(size_t)); 174 ngx_memzero(test, size * sizeof(u_short));
174 175
175 for (n = 0; n < nelts; n++) { 176 for (n = 0; n < nelts; n++) {
176 if (names[n].key.data == NULL) { 177 if (names[n].key.data == NULL) {
177 continue; 178 continue;
178 } 179 }
179 180
180 key = names[n].key_hash % size; 181 key = names[n].key_hash % size;
181 test[key] += NGX_HASH_ELT_SIZE(&names[n]); 182 test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));
182 183
183 #if 0 184 #if 0
184 ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, 185 ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0,
185 "%ui: %ui %ui \"%V\"", 186 "%ui: %ui %ui \"%V\"",
186 size, key, test[key], &names[n].key); 187 size, key, test[key], &names[n].key);
187 #endif 188 #endif
188 189
189 if (test[key] > bucket_size) { 190 if (test[key] > (u_short) bucket_size) {
190 goto next; 191 goto next;
191 } 192 }
192 } 193 }
193 194
194 goto found; 195 goto found;
197 198
198 continue; 199 continue;
199 } 200 }
200 201
201 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, 202 ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,
202 "could not build the %s hash, you should increase " 203 "could not build the %s, you should increase "
203 "either %s_max_size: %i or %s_bucket_size: %i", 204 "either %s_max_size: %i or %s_bucket_size: %i",
204 hinit->name, hinit->name, hinit->max_size, 205 hinit->name, hinit->name, hinit->max_size,
205 hinit->name, hinit->bucket_size); 206 hinit->name, hinit->bucket_size);
206 207
207 ngx_free(test); 208 ngx_free(test);
218 if (names[n].key.data == NULL) { 219 if (names[n].key.data == NULL) {
219 continue; 220 continue;
220 } 221 }
221 222
222 key = names[n].key_hash % size; 223 key = names[n].key_hash % size;
223 test[key] += NGX_HASH_ELT_SIZE(&names[n]); 224 test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));
224 } 225 }
225 226
226 len = 0; 227 len = 0;
227 228
228 for (i = 0; i < size; i++) { 229 for (i = 0; i < size; i++) {
229 if (test[i] == sizeof(void *)) { 230 if (test[i] == sizeof(void *)) {
230 continue; 231 continue;
231 } 232 }
232 233
233 test[i] = ngx_align(test[i], ngx_cacheline_size); 234 test[i] = (u_short) (ngx_align(test[i], ngx_cacheline_size));
234 235
235 len += test[i]; 236 len += test[i];
236 } 237 }
237 238
238 if (hinit->hash == NULL) { 239 if (hinit->hash == NULL) {
289 290
290 for (i = 0; i < names[n].key.len; i++) { 291 for (i = 0; i < names[n].key.len; i++) {
291 elt->name[i] = ngx_tolower(names[n].key.data[i]); 292 elt->name[i] = ngx_tolower(names[n].key.data[i]);
292 } 293 }
293 294
294 test[key] += NGX_HASH_ELT_SIZE(&names[n]); 295 test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));
295 } 296 }
296 297
297 for (i = 0; i < size; i++) { 298 for (i = 0; i < size; i++) {
298 if (buckets[i] == NULL) { 299 if (buckets[i] == NULL) {
299 continue; 300 continue;