From: Matthew Fernandez Date: Sat, 15 Oct 2022 21:25:22 +0000 (-0700) Subject: cgraph strview_str_contains: abbreviate prefix check X-Git-Tag: 7.0.1~11^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3567db13421cf993c661f2498a3b8c4cacf2b369;p=graphviz cgraph strview_str_contains: abbreviate prefix check After this function was written, the `startswith` helper was introduced for abbreviating the idiom `strncmp(foo, bar, strlen(bar)) == 0`. We can use it to more concisely and clearly express the intent of this code. --- diff --git a/lib/cgraph/strview.h b/lib/cgraph/strview.h index 8e4d593ad..28c78af58 100644 --- a/lib/cgraph/strview.h +++ b/lib/cgraph/strview.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -128,7 +129,7 @@ static inline bool strview_str_contains(strview_t haystack, } // is it a match? - if (strncmp(candidate, needle, strlen(needle)) == 0) { + if (startswith(candidate, needle)) { return true; }