From: Benjamin Kramer Date: Thu, 4 Oct 2012 10:06:38 +0000 (+0000) Subject: Prefer StringRef::startswith to the strncmp/strlen contraption. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbdc1a3432c897c11b6d256d556a8a11368729ad;p=clang Prefer StringRef::startswith to the strncmp/strlen contraption. This may be slightly more efficient and is definitely more readable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165217 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp index 257f3537a1..e108106fa7 100644 --- a/lib/Driver/OptTable.cpp +++ b/lib/Driver/OptTable.cpp @@ -159,10 +159,11 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const { // FIXME: This is searching much more than necessary, but I am // blanking on the simplest way to make it fast. We can solve this // problem when we move to TableGen. + StringRef StrRef(Str); for (; Start != End; ++Start) { // Scan for first option which is a proper prefix. for (; Start != End; ++Start) - if (strncmp(Str, Start->Name, strlen(Start->Name)) == 0) + if (StrRef.startswith(Start->Name)) break; if (Start == End) break;