mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-12-24 12:58:39 +00:00
Replace strcmp() with memcmp() where possible
memcmp() is always faster than strcmp(). In places where we already know that both buffers have sufficient size, replace strcmp() with memcmp(). * src/main.c (main): Replace strncmp() with memcmp()==0. * src/read.c (word1eq): Ditto. * src/commands.c (set_file_variables): Ditto. * src/function.c (func_filter_filterout): Ditto. (a_word_hash_cmp): Use STRING_N_COMPARE since we know the length. (func_sort): Replace strcmp() with memcmp().
This commit is contained in:
parent
9fa63eb918
commit
5690084634
4 changed files with 11 additions and 10 deletions
|
@ -121,8 +121,9 @@ set_file_variables (struct file *file, const char *stem)
|
|||
|
||||
for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
|
||||
{
|
||||
size_t slen = strlen (dep_name (d));
|
||||
if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
|
||||
const char *dn = dep_name (d);
|
||||
size_t slen = strlen (dn);
|
||||
if (len > slen && memcmp (dn, name + (len - slen), slen) == 0)
|
||||
{
|
||||
file->stem = stem = strcache_add_len (name, len - slen);
|
||||
break;
|
||||
|
|
|
@ -990,8 +990,9 @@ a_word_hash_cmp (const void *x, const void *y)
|
|||
int result = (int) ((struct a_word const *) x)->length - ((struct a_word const *) y)->length;
|
||||
if (result)
|
||||
return result;
|
||||
return_STRING_COMPARE (((struct a_word const *) x)->str,
|
||||
((struct a_word const *) y)->str);
|
||||
return_STRING_N_COMPARE (((struct a_word const *) x)->str,
|
||||
((struct a_word const *) y)->str,
|
||||
((struct a_word const *) y)->length);
|
||||
}
|
||||
|
||||
struct a_pattern
|
||||
|
@ -1110,7 +1111,7 @@ func_filter_filterout (char *o, char **argv, const char *funcname)
|
|||
else
|
||||
for (wp = words; wp < word_end; ++wp)
|
||||
wp->matched |= (wp->length == pp->length
|
||||
&& strneq (pp->str, wp->str, wp->length));
|
||||
&& memcmp (pp->str, wp->str, wp->length) == 0);
|
||||
}
|
||||
|
||||
/* Output the words that matched (or didn't, for filter-out). */
|
||||
|
@ -1245,7 +1246,7 @@ func_sort (char *o, char **argv, const char *funcname UNUSED)
|
|||
{
|
||||
len = strlen (words[i]);
|
||||
if (i == wordi - 1 || strlen (words[i + 1]) != len
|
||||
|| strcmp (words[i], words[i + 1]))
|
||||
|| memcmp (words[i], words[i + 1], len))
|
||||
{
|
||||
o = variable_buffer_output (o, words[i], len);
|
||||
o = variable_buffer_output (o, " ", 1);
|
||||
|
|
|
@ -1404,7 +1404,7 @@ main (int argc, char **argv, char **envp)
|
|||
|
||||
/* If this is MAKE_RESTARTS, check to see if the "already printed
|
||||
the enter statement" flag is set. */
|
||||
if (len == 13 && strneq (envp[i], "MAKE_RESTARTS", 13))
|
||||
if (len == 13 && memcmp (envp[i], "MAKE_RESTARTS", 13) == 0)
|
||||
{
|
||||
if (*ep == '-')
|
||||
{
|
||||
|
|
|
@ -164,9 +164,8 @@ static char *unescape_char (char *string, int c);
|
|||
|
||||
|
||||
/* Compare a word, both length and contents.
|
||||
P must point to the word to be tested, and WLEN must be the length.
|
||||
*/
|
||||
#define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
|
||||
P must point to the word to be tested, and WLEN must be the length. */
|
||||
#define word1eq(s) (wlen == CSTRLEN (s) && memcmp (s, p, CSTRLEN (s)) == 0)
|
||||
|
||||
|
||||
/* Read in all the makefiles and return a chain of targets to rebuild. */
|
||||
|
|
Loading…
Reference in a new issue