diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-12-21 06:49:24 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-12-21 06:49:24 +0000 |
commit | d5b1f8a8426e82990dafc6e3336fefc6635c8fa4 (patch) | |
tree | f36a127f324b061469393df77fddb0f8bcd59258 /include/llvm/ADT/StringRef.h | |
parent | 65f067fa638ce34329c96b8be133092e9be4ea83 (diff) |
Change StringRef::startswith and StringRef::endswith to versions which are a
bit more verbose, but optimize to much shorter code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringRef.h')
-rw-r--r-- | include/llvm/ADT/StringRef.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index f299f5fd65..a7442666d6 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -159,12 +159,14 @@ namespace llvm { /// startswith - Check if this string starts with the given \arg Prefix. bool startswith(StringRef Prefix) const { - return substr(0, Prefix.Length).equals(Prefix); + return Length >= Prefix.Length && + memcmp(Data, Prefix.Data, Prefix.Length) == 0; } /// endswith - Check if this string ends with the given \arg Suffix. bool endswith(StringRef Suffix) const { - return slice(size() - Suffix.Length, size()).equals(Suffix); + return Length >= Suffix.Length && + memcmp(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0; } /// @} |