From 3567db13421cf993c661f2498a3b8c4cacf2b369 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Oct 2022 14:25:22 -0700 Subject: [PATCH] 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. --- lib/cgraph/strview.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } -- 2.40.0