diff options
author | Olly Betts <olly@survex.com> | 2023-05-15 16:12:21 +1200 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2023-05-15 16:19:17 +1200 |
commit | 8a9628e2b900a4f62b52ab339ba35f50fedd1fd8 (patch) | |
tree | 95876839d875c2bedb8144dfda5a972df2757d73 /Source | |
parent | 10ca0edddb77e1a1a78e073b636af8d1f89eac41 (diff) | |
download | swig-8a9628e2b900a4f62b52ab339ba35f50fedd1fd8.tar.gz |
Use strchr/Strchr for single character searches
This can be more efficient than using strstr/Strstr with a single
character search string.
GCC is able to optimise strstr() with a single character literal
search string to strchr(), but clang doesn't, and likely no compiler
can for Strstr() (unless some sort of inter-object optimisation such
as LTO is used) since the literal string is in a different source file
to the strstr() call.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Modules/d.cxx | 6 | ||||
-rw-r--r-- | Source/Modules/emit.cxx | 2 | ||||
-rw-r--r-- | Source/Preprocessor/cpp.c | 10 | ||||
-rw-r--r-- | Source/Swig/cwrap.c | 2 | ||||
-rw-r--r-- | Source/Swig/stype.c | 4 | ||||
-rw-r--r-- | Source/Swig/typeobj.c | 2 |
6 files changed, 13 insertions, 13 deletions
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 7cc906049..3005dc163 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -4552,7 +4552,7 @@ private: char *tmp = Char(nspace); char *c = tmp; char *co = 0; - if (!strstr(c, ".")) + if (!strchr(c, '.')) return 0; co = c + Len(nspace); @@ -4579,7 +4579,7 @@ private: if (!nspace) return NULL; char *c = Char(nspace); char *cc = c; - if (!strstr(c, ".")) + if (!strchr(c, '.')) return NewString(nspace); while (*c) { @@ -4602,7 +4602,7 @@ private: char *tmp = Char(nspace); char *c = tmp; char *cc = c; - if (!strstr(c, ".")) + if (!strchr(c, '.')) return NULL; while (*c) { diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index 74adc5400..8476a0c6c 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -411,7 +411,7 @@ int emit_action_code(Node *n, String *wrappercode, String *eaction) { if (tm) tm = Copy(tm); if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - if (Strstr(tm, "$")) { + if (Strchr(tm, '$')) { Swig_replace_special_variables(n, parentNode(n), tm); Replaceall(tm, "$function", eaction); // deprecated Replaceall(tm, "$action", eaction); diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index ae1e2ecb5..840c9f1cb 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -905,7 +905,7 @@ static String *expand_macro(String *name, List *args, String *line_file) { arg = Getitem(args, i); /* Get an argument value */ reparg = Preprocessor_replace(arg, NULL); aname = Getitem(margs, i); /* Get macro argument name */ - if (strstr(Char(ns), "\001")) { + if (strchr(Char(ns), '\001')) { /* Try to replace a quoted version of the argument */ Clear(temp); Clear(tempa); @@ -913,7 +913,7 @@ static String *expand_macro(String *name, List *args, String *line_file) { Printf(tempa, "\"%s\"", arg); Replace(ns, temp, tempa, DOH_REPLACE_ID_END); } - if (strstr(Char(ns), "\002")) { + if (strchr(Char(ns), '\002')) { /* Look for concatenation tokens */ Clear(temp); Clear(tempa); @@ -937,7 +937,7 @@ static String *expand_macro(String *name, List *args, String *line_file) { Clear(temp); Printf(temp, "`%s`", aname); c = Char(arg); - if (*c == '\"') { + if (*c == '"') { rep = arg; } else { Clear(tempa); @@ -949,14 +949,14 @@ static String *expand_macro(String *name, List *args, String *line_file) { /* Non-standard mangle expansions. The #@Name is replaced by mangle_arg(Name). */ - if (strstr(Char(ns), "\004")) { + if (strchr(Char(ns), '\004')) { String *marg = Swig_name_mangle_string(arg); Clear(temp); Printf(temp, "\004%s", aname); Replace(ns, temp, marg, DOH_REPLACE_ID_END); Delete(marg); } - if (strstr(Char(ns), "\005")) { + if (strchr(Char(ns), '\005')) { String *marg = Swig_name_mangle_string(arg); Clear(temp); Clear(tempa); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index b4be5d728..96aa8c9c4 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -893,7 +893,7 @@ static String *extension_code(Node *n, const String *function_name, ParmList *pa String *rt_sig = SwigType_str(return_type, sig); String *body = NewStringf("SWIGINTERN %s", rt_sig); Printv(body, code, "\n", NIL); - if (Strstr(body, "$")) { + if (Strchr(body, '$')) { Swig_replace_special_variables(n, parentNode(parentNode(n)), body); if (self) Replaceall(body, "$self", self); diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 7a7b727a2..50857191b 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -1262,10 +1262,10 @@ static String *manglestr_default(const SwigType *s) { String *SwigType_manglestr(const SwigType *s) { #if 0 /* Debugging checks to ensure a proper SwigType is passed in and not a stringified type */ - String *angle = Strstr(s, "<"); + String *angle = Strchr(s, '<'); if (angle && Strncmp(angle, "<(", 2) != 0) Printf(stderr, "SwigType_manglestr error: %s\n", s); - else if (Strstr(s, "*") || Strstr(s, "&") || Strstr(s, "[")) + else if (Strchr(s, '*') || Strchr(s, '&') || Strchr(s, '[')) Printf(stderr, "SwigType_manglestr error: %s\n", s); #endif return manglestr_default(s); diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index d07de6e3d..74f5898f6 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -565,7 +565,7 @@ SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { const char *cqual = Char(qual); /* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */ - if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == 0)) { + if ((strncmp(c, "q(", 2) != 0) && (strchr(cqual, ' ') == 0)) { String *temp = NewStringf("q(%s).", cqual); Insert(t, 0, temp); Delete(temp); |