Changeset 903 in kBuild for trunk/src/gmakenew/strcache.c
- Timestamp:
- May 23, 2007 5:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/strcache.c
r503 r903 21 21 #include "hash.h" 22 22 23 /* The size (in bytes) of each cache buffer. */ 24 #define CACHE_BUFFER_SIZE (4096) 23 /* The size (in bytes) of each cache buffer. 24 Try to pick something that will map well into the heap. */ 25 #define CACHE_BUFFER_SIZE (8192 - 16) 25 26 26 27 … … 40 41 static struct strcache *strcache = NULL; 41 42 43 /* Add a new buffer to the cache. Add it at the front to reduce search time. 44 This can also increase the overhead, since it's less likely that older 45 buffers will be filled in. However, GNU make has so many smaller strings 46 that this doesn't seem to be much of an issue in practice. 47 */ 42 48 static struct strcache * 43 49 new_cache() 44 50 { 45 51 struct strcache *new; 46 new = (struct strcache *)xmalloc (sizeof (*new) + bufsize);52 new = xmalloc (sizeof (*new) + bufsize); 47 53 new->end = new->buffer; 48 54 new->count = 0; … … 62 68 const char *res; 63 69 64 /* If the string we want is too large to fit into a single buffer, then we're65 screwed; nothing will ever fit! Change the maximum size of the cache to66 be big enough. */70 /* If the string we want is too large to fit into a single buffer, then 71 we're screwed; nothing will ever fit! Change the maximum size of the 72 cache to be big enough. */ 67 73 if (len > bufsize) 68 74 bufsize = len * 2; … … 114 120 115 121 static struct hash_table strings; 122 static unsigned long total_adds = 0; 116 123 117 124 static const char * … … 119 126 { 120 127 /* Look up the string in the hash. If it's there, return it. */ 121 char * *slot = (char **) hash_find_slot (&strings, str);128 char *const *slot = (char *const *) hash_find_slot (&strings, str); 122 129 const char *key = *slot; 130 131 /* Count the total number of adds we performed. */ 132 ++total_adds; 123 133 124 134 if (!HASH_VACANT (key)) … … 156 166 strcache_add_len (const char *str, int len) 157 167 { 158 char *key = alloca (len + 1); 159 memcpy (key, str, len); 160 key[len] = '\0'; 161 162 return add_hash (key, len); 168 /* If we're not given a nul-terminated string we have to create one, because 169 the hashing functions expect it. */ 170 if (str[len] != '\0') 171 { 172 char *key = alloca (len + 1); 173 memcpy (key, str, len); 174 key[len] = '\0'; 175 str = key; 176 } 177 178 return add_hash (str, len); 163 179 } 164 180 … … 174 190 strcache_init (void) 175 191 { 176 hash_init (&strings, 1000, str_hash_1, str_hash_2, str_hash_cmp);192 hash_init (&strings, 8000, str_hash_1, str_hash_2, str_hash_cmp); 177 193 } 178 194 … … 186 202 int totsize = 0, avgsize, maxsize = 0, minsize = bufsize; 187 203 int totfree = 0, avgfree, maxfree = 0, minfree = bufsize; 188 const struct strcache *sp;189 190 for (sp = strcache; sp != NULL; sp = sp->next)204 int lastused = 0, lastfree = 0; 205 206 if (strcache) 191 207 { 192 int bf = sp->bytesfree; 193 int sz = (sp->end - sp->buffer) + bf; 194 195 ++numbuffs; 196 numstrs += sp->count; 197 198 totsize += sz; 199 maxsize = (sz > maxsize ? sz : maxsize); 200 minsize = (sz < minsize ? sz : minsize); 201 202 totfree += bf; 203 maxfree = (bf > maxfree ? bf : maxfree); 204 minfree = (bf < minfree ? bf : minfree); 208 const struct strcache *sp; 209 210 /* Count the first buffer separately since it's not full. */ 211 lastused = strcache->end - strcache->buffer; 212 lastfree = strcache->bytesfree; 213 214 for (sp = strcache->next; sp != NULL; sp = sp->next) 215 { 216 int bf = sp->bytesfree; 217 int sz = sp->end - sp->buffer; 218 219 ++numbuffs; 220 numstrs += sp->count; 221 222 totsize += sz; 223 maxsize = (sz > maxsize ? sz : maxsize); 224 minsize = (sz < minsize ? sz : minsize); 225 226 totfree += bf; 227 maxfree = (bf > maxfree ? bf : maxfree); 228 minfree = (bf < minfree ? bf : minfree); 229 } 205 230 } 206 231 … … 208 233 avgfree = numbuffs ? (int)(totfree / numbuffs) : 0; 209 234 210 printf (_("\n%s # of strings in strcache: %d\n"), prefix, numstrs); 211 printf (_("%s # of strcache buffers: %d\n"), prefix, numbuffs); 212 printf (_("%s strcache size: total = %d / max = %d / min = %d / avg = %d\n"), 213 prefix, totsize, maxsize, minsize, avgsize); 214 printf (_("%s strcache free: total = %d / max = %d / min = %d / avg = %d\n"), 215 prefix, totfree, maxfree, minfree, avgfree); 216 } 235 printf (_("\n%s # of strings in strcache: %d / lookups = %lu / hits = %lu\n"), 236 prefix, numstrs, total_adds, (total_adds - numstrs)); 237 printf (_("%s # of strcache buffers: %d (* %d B/buffer = %d B)\n"), 238 prefix, (numbuffs + 1), bufsize, ((numbuffs + 1) * bufsize)); 239 printf (_("%s strcache used: total = %d (%d) / max = %d / min = %d / avg = %d\n"), 240 prefix, totsize, lastused, maxsize, minsize, avgsize); 241 printf (_("%s strcache free: total = %d (%d) / max = %d / min = %d / avg = %d\n"), 242 prefix, totfree, lastfree, maxfree, minfree, avgfree); 243 244 fputs (_("\n# strcache hash-table stats:\n# "), stdout); 245 hash_print_stats (&strings, stdout); 246 }
Note:
See TracChangeset
for help on using the changeset viewer.