Changeset 1857 for trunk/src/kmk/file.c
- Timestamp:
- Oct 13, 2008, 5:58:07 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/file.c
r1851 r1857 41 41 /* Hash table of files the makefile knows how to make. */ 42 42 43 #ifndef KMK 43 44 static unsigned long 44 45 file_hash_1 (const void *key) … … 56 57 file_hash_cmp (const void *x, const void *y) 57 58 { 58 #ifdef KMK 59 /* since the names live in the strcache, there is a raging likelylood 60 that we'll match on the string pointer. Which is wee bit faster... */ 61 struct file const *xf = ((struct file const *) x); 62 struct file const *yf = ((struct file const *) y); 59 return_ISTRING_COMPARE (((struct file const *) x)->hname, 60 ((struct file const *) y)->hname); 61 } 62 #else /* KMK */ 63 64 static unsigned long 65 file_hash_1 (const void *key) 66 { 67 struct file const *f = (struct file const *)key; 68 69 /* If it's cached, get the hash from the strcache. */ 70 if (f->name != (const char *)f) 71 return strcache_get_hash1 (f->hname); 72 73 return_ISTRING_HASH_1 (f->hname); 74 } 75 76 static unsigned long 77 file_hash_2 (const void *key) 78 { 79 struct file const *f = (struct file const *)key; 80 81 /* If it's cached, get the hash from the strcache. */ 82 if (f->name != (const char *)f) 83 return strcache_get_hash2 (f->hname); 84 85 return_ISTRING_HASH_2 (f->hname); 86 } 87 88 static int 89 file_hash_cmp (const void *x, const void *y) 90 { 91 struct file const *xf = ((struct file const *) x); 92 struct file const *yf = ((struct file const *) y); 93 94 /* The file name strings all live in the strcache. However, 95 lookup_file may or may not have a string from the cache. It indicates 96 that it's responsible for the lookup by setting file::name to point 97 to the file structure itself. So, when file::name points elsewhere 98 we can omit the string compare, while when it isn't we can only 99 check if they match that way. */ 100 63 101 if (xf->hname == yf->hname) 64 102 return 0; 103 if ( xf->name != (const char *)xf 104 && yf->name != (const char *)yf) 105 return 1; 106 65 107 return_ISTRING_COMPARE (xf->hname, yf->hname); 66 #else 67 return_ISTRING_COMPARE (((struct file const *) x)->hname, 68 ((struct file const *) y)->hname); 69 #endif 70 } 108 } 109 110 #endif /* KMK */ 71 111 72 112 #ifndef FILE_BUCKETS … … 83 123 */ 84 124 125 #ifndef KMK 85 126 struct file * 86 127 lookup_file (const char *name) 128 #else /* KMK */ 129 MY_INLINE struct file * 130 lookup_file_common (const char *name, int cached) 131 #endif /* KMK */ 87 132 { 88 133 struct file *f; … … 132 177 #endif 133 178 179 #ifdef KMK 180 /* uncached lookup indicator hack. */ 181 file_key.name = !cached ? (const char *)&file_key : NULL; 182 #endif 134 183 file_key.hname = name; 135 184 f = hash_find_item (&files, &file_key); … … 141 190 return f; 142 191 } 192 193 #ifdef KMK 194 /* Given a name, return the struct file * for that name, 195 or nil if there is none. */ 196 197 struct file * 198 lookup_file (const char *name) 199 { 200 return lookup_file_common (name, 0 /* cached */); 201 } 202 203 /* Given a name in the strcache, return the struct file * for that name, 204 or nil if there is none. */ 205 struct file * 206 lookup_file_cached (const char *name) 207 { 208 assert (strcache_iscached (name)); 209 return lookup_file_common (name, 1 /* cached */); 210 } 211 #endif /* KMK */ 212 143 213 144 214 /* Look up a file record for file NAME and return it. … … 222 292 struct file *deleted_file; 223 293 struct file *f; 294 295 #ifdef KMK 296 assert (strcache_iscached (to_hname)); 297 assert (strcache_iscached (from_file->hname)); 298 file_key.name = NULL; /* cached lookup indicator hack. */ 299 #endif 224 300 225 301 /* If it's already that name, we're done. */
Note:
See TracChangeset
for help on using the changeset viewer.