Changeset 1903 in kBuild
- Timestamp:
- Oct 21, 2008 4:25:19 AM (16 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/file.c
r1902 r1903 140 140 if (!cached) 141 141 { 142 file_key.hname = strcache2_lookup (&file_strcache, name, strlen (name));142 file_key.hname = strcache2_lookup_file (&file_strcache, name, strlen (name)); 143 143 if (file_key.hname) 144 144 f = hash_find_item_strcached (&files, &file_key); -
trunk/src/kmk/incdep.c
r1895 r1903 769 769 { 770 770 if (!entry->user) 771 entry->user = (void *)strcache2_add_hashed (&file_strcache,772 (const char *)(entry + 1),773 entry->length,774 entry->hash1,775 entry->hash2);771 entry->user = (void *)strcache2_add_hashed_file (&file_strcache, 772 (const char *)(entry + 1), 773 entry->length, 774 entry->hash1, 775 entry->hash2); 776 776 return (const char *)entry->user; 777 777 } -
trunk/src/kmk/strcache2.c
r1899 r1903 268 268 } 269 269 270 #if 0 /* FIXME: Use this (salvaged from variable.c) */ 270 #ifdef _MSC_VER 271 typedef unsigned int int32_t; 272 #else 273 # include <stdint.h> 274 #endif 271 275 272 276 MY_INLINE int 273 variable_hash_cmp_2_memcmp(const char *xs, const char *ys, unsigned int length)277 strcache2_memcmp_inline_short (const char *xs, const char *ys, unsigned int length) 274 278 { 275 279 /* short string compare - ~50% of the kBuild calls. */ … … 345 349 346 350 MY_INLINE int 347 variable_hash_cmp_2_inlined (const char *xs, const char *ys, unsigned int length)351 strcache2_memcmp_inlined (const char *xs, const char *ys, unsigned int length) 348 352 { 349 353 #ifndef ELECTRIC_HEAP … … 450 454 } 451 455 452 #endif453 454 456 MY_INLINE int 455 457 strcache2_is_equal (struct strcache2 *cache, struct strcache2_entry const *entry, 456 458 const char *str, unsigned int length, unsigned int hash1) 457 459 { 460 assert (!cache->case_insensitive); 461 458 462 /* the simple stuff first. */ 459 463 if ( entry == NULL … … 462 466 return 0; 463 467 464 return !cache->case_insensitive 465 ? memcmp (entry + 1, str, length) == 0 468 #if 1 469 return memcmp (entry + 1, str, length) == 0; 470 #elif 0 471 return strcache2_memcmp_inlined (entry + 1, str, length) == 0; 472 #else 473 return strcache2_memcmp_inline_short (entry + 1, str, length) == 0; 474 #endif 475 } 476 477 MY_INLINE int 478 strcache2_is_iequal (struct strcache2 *cache, struct strcache2_entry const *entry, 479 const char *str, unsigned int length, unsigned int hash1) 480 { 481 assert (cache->case_insensitive); 482 483 /* the simple stuff first. */ 484 if ( entry == NULL 485 || entry->hash1 != hash1 486 || entry->length != length) 487 return 0; 488 466 489 #if defined(_MSC_VER) || defined(__OS2__) 467 : _memicmp (entry + 1, str, length) == 0490 return _memicmp (entry + 1, str, length) == 0; 468 491 #else 469 : strncasecmp ((const char *)(entry + 1), str, length) == 0492 return strncasecmp ((const char *)(entry + 1), str, length) == 0; 470 493 #endif 471 ;472 494 } 473 495 … … 632 654 unsigned correct_hash; 633 655 634 correct_hash = cache->case_insensitive 635 ? strcache2_case_insensitive_hash_1 (str, length) 636 : strcache2_case_sensitive_hash_1 (str, length); 656 assert (!cache->case_insensitive); 657 correct_hash = strcache2_case_sensitive_hash_1 (str, length); 637 658 MY_ASSERT_MSG (hash1 == correct_hash, ("%#x != %#x\n", hash1, correct_hash)); 638 659 if (hash2) 639 660 { 640 correct_hash = cache->case_insensitive 641 ? strcache2_case_insensitive_hash_2 (str, length) 642 : strcache2_case_sensitive_hash_2 (str, length); 661 correct_hash = strcache2_case_sensitive_hash_2 (str, length); 643 662 MY_ASSERT_MSG (hash2 == correct_hash, ("%#x != %#x\n", hash2, correct_hash)); 644 663 } … … 687 706 } 688 707 689 /* The public lookup string interface. */708 /* The public lookup (case sensitive) string interface. */ 690 709 const char * 691 710 strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length) … … 757 776 idx = hash1 & cache->hash_mask; 758 777 entry = cache->hash_tab[idx]; 759 if (strcache2_is_ equal (cache, entry, str, length, hash1))778 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 760 779 return (const char *)(entry + 1); 761 780 if (!entry) … … 769 788 idx &= cache->hash_mask; 770 789 entry = cache->hash_tab[idx]; 771 if (strcache2_is_ equal (cache, entry, str, length, hash1))790 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 772 791 return (const char *)(entry + 1); 773 792 … … 781 800 entry = cache->hash_tab[idx]; 782 801 cache->collision_3rd_count++; 783 if (strcache2_is_ equal (cache, entry, str, length, hash1))802 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 784 803 return (const char *)(entry + 1); 785 804 } … … 792 811 } 793 812 794 /* strcache_ilookup later */ 813 /* The public add string interface for prehashed case insensitive strings. 814 Use strcache2_hash_istr to calculate the hash of a string. */ 815 const char * 816 strcache2_iadd_hashed (struct strcache2 *cache, const char *str, unsigned int length, 817 unsigned int hash1, unsigned int hash2) 818 { 819 struct strcache2_entry const *entry; 820 unsigned int idx; 821 #ifndef NDEBUG 822 unsigned correct_hash; 823 824 assert (cache->case_insensitive); 825 correct_hash = strcache2_case_insensitive_hash_1 (str, length); 826 MY_ASSERT_MSG (hash1 == correct_hash, ("%#x != %#x\n", hash1, correct_hash)); 827 if (hash2) 828 { 829 correct_hash = strcache2_case_insensitive_hash_2 (str, length); 830 MY_ASSERT_MSG (hash2 == correct_hash, ("%#x != %#x\n", hash2, correct_hash)); 831 } 832 #endif /* NDEBUG */ 833 834 cache->lookup_count++; 835 836 /* Lookup the entry in the hash table, hoping for an 837 early match. */ 838 idx = hash1 & cache->hash_mask; 839 entry = cache->hash_tab[idx]; 840 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 841 return (const char *)(entry + 1); 842 if (entry) 843 { 844 cache->collision_1st_count++; 845 846 if (!hash2) 847 hash2 = strcache2_case_insensitive_hash_2 (str, length); 848 idx += hash2; 849 idx &= cache->hash_mask; 850 entry = cache->hash_tab[idx]; 851 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 852 return (const char *)(entry + 1); 853 854 if (entry) 855 { 856 cache->collision_2nd_count++; 857 do 858 { 859 idx += hash2; 860 idx &= cache->hash_mask; 861 entry = cache->hash_tab[idx]; 862 cache->collision_3rd_count++; 863 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 864 return (const char *)(entry + 1); 865 } 866 while (entry); 867 } 868 } 869 870 /* Not found, add it at IDX. */ 871 return strcache2_enter_string (cache, idx, str, length, hash1, hash2); 872 } 873 874 /* The public lookup (case insensitive) string interface. */ 875 const char * 876 strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length) 877 { 878 struct strcache2_entry const *entry; 879 unsigned int hash2; 880 unsigned int hash1 = strcache2_case_insensitive_hash_1 (str, length); 881 unsigned int idx; 882 883 assert (cache->case_insensitive); 884 885 cache->lookup_count++; 886 887 /* Lookup the entry in the hash table, hoping for an 888 early match. */ 889 idx = hash1 & cache->hash_mask; 890 entry = cache->hash_tab[idx]; 891 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 892 return (const char *)(entry + 1); 893 if (!entry) 894 hash2 = 0; 895 else 896 { 897 cache->collision_1st_count++; 898 899 hash2 = strcache2_case_insensitive_hash_2 (str, length); 900 idx += hash2; 901 idx &= cache->hash_mask; 902 entry = cache->hash_tab[idx]; 903 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 904 return (const char *)(entry + 1); 905 906 if (entry) 907 { 908 cache->collision_2nd_count++; 909 do 910 { 911 idx += hash2; 912 idx &= cache->hash_mask; 913 entry = cache->hash_tab[idx]; 914 cache->collision_3rd_count++; 915 if (strcache2_is_iequal (cache, entry, str, length, hash1)) 916 return (const char *)(entry + 1); 917 } 918 while (entry); 919 } 920 } 921 922 /* Not found. */ 923 return NULL; 924 } 795 925 796 926 #endif /* HAVE_CASE_INSENSITIVE_FS */ -
trunk/src/kmk/strcache2.h
r1900 r1903 95 95 const char *strcache2_add (struct strcache2 *cache, const char *str, unsigned int length); 96 96 const char *strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length); 97 #ifdef HAVE_CASE_INSENSITIVE_FS98 # define strcache2_add_file(cache, str, length) strcache2_iadd((cache), (str), (length))99 #else100 # define strcache2_add_file(cache, str, length) strcache2_add((cache), (str), (length))101 #endif102 97 const char *strcache2_add_hashed (struct strcache2 *cache, const char *str, unsigned int length, 103 98 unsigned int hash1, unsigned int hash2); 99 const char *strcache2_iadd_hashed (struct strcache2 *cache, const char *str, unsigned int length, 100 unsigned int hash1, unsigned int hash2); 104 101 const char *strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length); 102 const char *strcache2_ilookup (struct strcache2 *cache, const char *str, unsigned int length); 103 #ifdef HAVE_CASE_INSENSITIVE_FS 104 # define strcache2_add_file strcache2_iadd 105 # define strcache2_add_hashed_file strcache2_iadd_hashed 106 # define strcache2_lookup_file strcache2_ilookup 107 #else 108 # define strcache2_add_file strcache2_add 109 # define strcache2_add_hashed_file strcache2_add_hashed 110 # define strcache2_lookup_file strcache2_lookup 111 #endif 105 112 int strcache2_is_cached (struct strcache2 *cache, const char *str); 106 113 int strcache2_verify_entry (struct strcache2 *cache, const char *str);
Note:
See TracChangeset
for help on using the changeset viewer.