Hi, On Fri, 26 Aug 2011, Jakub Jelinek wrote:
> While you are touching it, I think we should also optimize it as in the > patch below. I'm afraid no string length optimization would be able to > figure out that it doesn't have to call strlen twice, because the > htab_find_slot isn't pure. Sure. Regstrapped the below patch and checked in as r178118. Ciao, Michael. -- Index: lto-streamer-in.c =================================================================== --- lto-streamer-in.c (revision 178117) +++ lto-streamer-in.c (revision 178118) @@ -98,21 +98,22 @@ canon_file_name (const char *string) { void **slot; struct string_slot s_slot; + size_t len = strlen (string); + s_slot.s = string; - s_slot.len = strlen (string); + s_slot.len = len; slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT); if (*slot == NULL) { - size_t len; char *saved_string; struct string_slot *new_slot; - len = strlen (string); saved_string = (char *) xmalloc (len + 1); new_slot = XCNEW (struct string_slot); - strcpy (saved_string, string); + memcpy (saved_string, string, len + 1); new_slot->s = saved_string; + new_slot->len = len; *slot = new_slot; return saved_string; }