]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Inline Util::{starts,ends}_with
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 07:43:53 +0000 (09:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 07:43:53 +0000 (09:43 +0200)
src/Util.cpp
src/Util.hpp

index 0476bc2249529ddf3fe30ab9fbcfd5e9a4f9a013..c2cb37b43b1eac04e72e74478479314c6b91f911 100644 (file)
@@ -369,12 +369,6 @@ dir_name(string_view path)
   }
 }
 
-bool
-ends_with(string_view string, string_view suffix)
-{
-  return string.ends_with(suffix);
-}
-
 std::string
 expand_environment_variables(const std::string& str)
 {
@@ -1137,20 +1131,6 @@ split_into_strings(string_view input, const char* separators)
   return split_at<std::string>(input, separators);
 }
 
-bool
-starts_with(const char* string, nonstd::string_view prefix)
-{
-  // Optimized version of starts_with(string_view, string_view): avoid computing
-  // the length of the string argument.
-  return strncmp(string, prefix.data(), prefix.length()) == 0;
-}
-
-bool
-starts_with(string_view string, string_view prefix)
-{
-  return string.starts_with(prefix);
-}
-
 std::string
 strip_ansi_csi_seqs(string_view string)
 {
index 149d709ff038b63f04412570eed7b8f497ecf143..000f4b855eac0cb04549e5b960ec6df6ad5ca3cc 100644 (file)
@@ -120,8 +120,12 @@ bool create_dir(nonstd::string_view dir);
 // Get directory name of path.
 nonstd::string_view dir_name(nonstd::string_view path);
 
-// Return true if suffix is a suffix of string.
-bool ends_with(nonstd::string_view string, nonstd::string_view suffix);
+// Return true if `suffix` is a suffix of `string`.
+inline bool
+ends_with(nonstd::string_view string, nonstd::string_view suffix)
+{
+  return string.ends_with(suffix);
+}
 
 // Expand all instances of $VAR or ${VAR}, where VAR is an environment variable,
 // in `str`. Throws `Error` if one of the environment variables.
@@ -357,8 +361,20 @@ std::vector<std::string> split_into_strings(nonstd::string_view input,
                                             const char* separators);
 
 // Return true if `prefix` is a prefix of `string`.
-bool starts_with(const char* string, nonstd::string_view prefix);
-bool starts_with(nonstd::string_view string, nonstd::string_view prefix);
+inline bool
+starts_with(const char* string, nonstd::string_view prefix)
+{
+  // Optimized version of starts_with(string_view, string_view): avoid computing
+  // the length of the string argument.
+  return strncmp(string, prefix.data(), prefix.length()) == 0;
+}
+
+// Return true if `prefix` is a prefix of `string`.
+inline bool
+starts_with(nonstd::string_view string, nonstd::string_view prefix)
+{
+  return string.starts_with(prefix);
+}
 
 // Returns a copy of string with the specified ANSI CSI sequences removed.
 [[gnu::warn_unused_result]] std::string