diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2022-04-24 17:43:56 -0400 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2022-04-24 17:52:54 -0400 |
commit | 5690084634b507ad7427589a9525eca05d15eb4f (patch) | |
tree | 0c0ea9a6af185afddd60e01104c93df2eff9688c /src/function.c | |
parent | 9fa63eb918e965d6704f33c1b124d14357af9911 (diff) | |
download | make-git-5690084634b507ad7427589a9525eca05d15eb4f.tar.gz |
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().
Diffstat (limited to 'src/function.c')
-rw-r--r-- | src/function.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/function.c b/src/function.c index 38ab9667..89449a8f 100644 --- a/src/function.c +++ b/src/function.c @@ -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); |