]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve language_for_file signature
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 1 Jun 2024 11:01:23 +0000 (13:01 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 Jun 2024 15:18:49 +0000 (17:18 +0200)
src/ccache/language.cpp
src/ccache/language.hpp

index 66522de00da8a49e02809f1ce6c79c5fcf81c818..41db79a4df3334ae042dfd465046e1087b8b2225 100644 (file)
@@ -104,10 +104,10 @@ const struct
 
 } // namespace
 
-std::string
-language_for_file(const std::string& fname, CompilerType compiler_type)
+std::string_view
+language_for_file(const fs::path& path, CompilerType compiler_type)
 {
-  const auto ext = fs::path(fname).extension();
+  const auto ext = path.extension();
   if (ext == ".cu" && compiler_type == CompilerType::clang) {
     // Special case: Clang maps .cu to cuda.
     return "cuda";
index 1ab0f977c98fa3cc328a06ed99bb1d760d3c1be3..c58f1aa2f1ca266f6bc399c758c22fda4fd6d0f0 100644 (file)
 
 #include <ccache/Config.hpp>
 
+#include <filesystem>
 #include <string>
+#include <string_view>
 
-// Guess the language of `fname` based on its extension and a compiler type.
+// Guess the language of `path` based on its extension and a compiler type.
 // Returns the empty string if the extension is unknown.
-std::string language_for_file(const std::string& fname,
-                              CompilerType compiler_type);
+std::string_view language_for_file(const std::filesystem::path& path,
+                                   CompilerType compiler_type);
 
 // Return the preprocessed language for `language`, or the empty string if
 // unknown.