Changeset 1887 for trunk/src/kmk/strcache2.c
- Timestamp:
- Oct 20, 2008, 1:08:10 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/strcache2.c
r1885 r1887 259 259 } 260 260 261 #if 0 /* FIXME: Use this (salvaged from variable.c) */ 262 263 MY_INLINE int 264 variable_hash_cmp_2_memcmp (const char *xs, const char *ys, unsigned int length) 265 { 266 /* short string compare - ~50% of the kBuild calls. */ 267 assert ( !((size_t)ys & 3) ); 268 if (!((size_t)xs & 3)) 269 { 270 /* aligned */ 271 int result; 272 switch (length) 273 { 274 case 8: 275 result = *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4); 276 result |= *(int32_t*)xs - *(int32_t*)ys; 277 return result; 278 case 7: 279 result = xs[6] - ys[6]; 280 result |= xs[5] - ys[5]; 281 result |= xs[4] - ys[4]; 282 result |= *(int32_t*)xs - *(int32_t*)ys; 283 return result; 284 case 6: 285 result = xs[5] - ys[5]; 286 result |= xs[4] - ys[4]; 287 result |= *(int32_t*)xs - *(int32_t*)ys; 288 return result; 289 case 5: 290 result = xs[4] - ys[4]; 291 result |= *(int32_t*)xs - *(int32_t*)ys; 292 return result; 293 case 4: 294 return *(int32_t*)xs - *(int32_t*)ys; 295 case 3: 296 result = xs[2] - ys[2]; 297 result |= xs[1] - ys[1]; 298 result |= xs[0] - ys[0]; 299 return result; 300 case 2: 301 result = xs[1] - ys[1]; 302 result |= xs[0] - ys[0]; 303 return result; 304 case 1: 305 return *xs - *ys; 306 case 0: 307 return 0; 308 } 309 } 310 else 311 { 312 /* unaligned */ 313 int result = 0; 314 switch (length) 315 { 316 case 8: result |= xs[7] - ys[7]; 317 case 7: result |= xs[6] - ys[6]; 318 case 6: result |= xs[5] - ys[5]; 319 case 5: result |= xs[4] - ys[4]; 320 case 4: result |= xs[3] - ys[3]; 321 case 3: result |= xs[2] - ys[2]; 322 case 2: result |= xs[1] - ys[1]; 323 case 1: result |= xs[0] - ys[0]; 324 case 0: 325 return result; 326 } 327 } 328 329 /* memcmp for longer strings */ 330 # ifdef __GNUC__ 331 return __builtin_memcmp (xs, ys, length); 332 # else 333 return memcmp (xs, ys, length); 334 # endif 335 } 336 337 MY_INLINE int 338 variable_hash_cmp_2_inlined (const char *xs, const char *ys, unsigned int length) 339 { 340 #ifndef ELECTRIC_HEAP 341 assert ( !((size_t)ys & 3) ); 342 #endif 343 if (!((size_t)xs & 3)) 344 { 345 int result; 346 /* aligned */ 347 while (length >= 8) 348 { 349 result = *(int32_t*)xs - *(int32_t*)ys; 350 result |= *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4); 351 if (MY_PREDICT_FALSE(result)) 352 return result; 353 xs += 8; 354 ys += 8; 355 length -= 8; 356 } 357 switch (length) 358 { 359 case 7: 360 result = *(int32_t*)xs - *(int32_t*)ys; 361 result |= xs[6] - ys[6]; 362 result |= xs[5] - ys[5]; 363 result |= xs[4] - ys[4]; 364 return result; 365 case 6: 366 result = *(int32_t*)xs - *(int32_t*)ys; 367 result |= xs[5] - ys[5]; 368 result |= xs[4] - ys[4]; 369 return result; 370 case 5: 371 result = *(int32_t*)xs - *(int32_t*)ys; 372 result |= xs[4] - ys[4]; 373 return result; 374 case 4: 375 return *(int32_t*)xs - *(int32_t*)ys; 376 case 3: 377 result = xs[2] - ys[2]; 378 result |= xs[1] - ys[1]; 379 result |= xs[0] - ys[0]; 380 return result; 381 case 2: 382 result = xs[1] - ys[1]; 383 result |= xs[0] - ys[0]; 384 return result; 385 case 1: 386 return *xs - *ys; 387 default: 388 case 0: 389 return 0; 390 } 391 } 392 else 393 { 394 /* unaligned */ 395 int result; 396 while (length >= 8) 397 { 398 #if defined(__i386__) || defined(__x86_64__) 399 result = ( ((int32_t)xs[3] << 24) 400 | ((int32_t)xs[2] << 16) 401 | ((int32_t)xs[1] << 8) 402 | xs[0] ) 403 - *(int32_t*)ys; 404 result |= ( ((int32_t)xs[7] << 24) 405 | ((int32_t)xs[6] << 16) 406 | ((int32_t)xs[5] << 8) 407 | xs[4] ) 408 - *(int32_t*)(ys + 4); 409 #else 410 result = xs[3] - ys[3]; 411 result |= xs[2] - ys[2]; 412 result |= xs[1] - ys[1]; 413 result |= xs[0] - ys[0]; 414 result |= xs[7] - ys[7]; 415 result |= xs[6] - ys[6]; 416 result |= xs[5] - ys[5]; 417 result |= xs[4] - ys[4]; 418 #endif 419 if (MY_PREDICT_FALSE(result)) 420 return result; 421 xs += 8; 422 ys += 8; 423 length -= 8; 424 } 425 result = 0; 426 switch (length) 427 { 428 case 7: result |= xs[6] - ys[6]; 429 case 6: result |= xs[5] - ys[5]; 430 case 5: result |= xs[4] - ys[4]; 431 case 4: result |= xs[3] - ys[3]; 432 case 3: result |= xs[2] - ys[2]; 433 case 2: result |= xs[1] - ys[1]; 434 case 1: result |= xs[0] - ys[0]; 435 return result; 436 default: 437 case 0: 438 return 0; 439 } 440 } 441 } 442 443 #endif 444 261 445 MY_INLINE int 262 446 strcache2_is_equal (struct strcache2 *cache, struct strcache2_entry const *entry, … … 375 559 } 376 560 377 /* The public add /lookupstring interface. */561 /* The public add string interface. */ 378 562 const char * 379 563 strcache2_add (struct strcache2 *cache, const char *str, unsigned int length) … … 428 612 } 429 613 430 /* The public add /lookupstring interface for prehashed strings.614 /* The public add string interface for prehashed strings. 431 615 Use strcache2_hash_str to calculate the hash of a string. */ 432 616 const char * … … 494 678 } 495 679 680 /* The public lookup string interface. */ 681 const char * 682 strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length) 683 { 684 struct strcache2_entry const *entry; 685 unsigned int hash2; 686 unsigned int hash1 = strcache2_case_sensitive_hash_1 (str, length); 687 unsigned int idx; 688 689 assert (!cache->case_insensitive); 690 691 cache->lookup_count++; 692 693 /* Lookup the entry in the hash table, hoping for an 694 early match. */ 695 idx = hash1 & cache->hash_mask; 696 entry = cache->hash_tab[idx]; 697 if (strcache2_is_equal (cache, entry, str, length, hash1)) 698 return (const char *)(entry + 1); 699 if (!entry) 700 hash2 = 0; 701 else 702 { 703 cache->collision_1st_count++; 704 705 hash2 = strcache2_case_sensitive_hash_2 (str, length); 706 idx += hash2; 707 idx &= cache->hash_mask; 708 entry = cache->hash_tab[idx]; 709 if (strcache2_is_equal (cache, entry, str, length, hash1)) 710 return (const char *)(entry + 1); 711 712 if (entry) 713 { 714 cache->collision_2nd_count++; 715 do 716 { 717 idx += hash2; 718 idx &= cache->hash_mask; 719 entry = cache->hash_tab[idx]; 720 cache->collision_3rd_count++; 721 if (strcache2_is_equal (cache, entry, str, length, hash1)) 722 return (const char *)(entry + 1); 723 } 724 while (entry); 725 } 726 } 727 728 /* Not found. */ 729 return NULL; 730 } 731 496 732 #if defined(HAVE_CASE_INSENSITIVE_FS) 497 733 498 /* The public add /lookupstring interface for case insensitive strings. */734 /* The public add string interface for case insensitive strings. */ 499 735 const char * 500 736 strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length)
Note:
See TracChangeset
for help on using the changeset viewer.