diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -329,8 +329,8 @@ /// filename has no extension, ConstString(nullptr) is returned. The dot /// ('.') character is the first character in the returned string. /// - /// \return Returns the extension of the file as a ConstString object. - ConstString GetFileNameExtension() const; + /// \return Returns the extension of the file as a StringRef. + llvm::StringRef GetFileNameExtension() const; /// Return the filename without the extension part /// diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -2163,7 +2163,7 @@ const char *pcm_path = command.GetArgumentAtIndex(0); FileSpec pcm_file{pcm_path}; - if (pcm_file.GetFileNameExtension().GetStringRef() != ".pcm") { + if (pcm_file.GetFileNameExtension() != ".pcm") { result.AppendError("file must have a .pcm extension"); return false; } diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -607,8 +607,8 @@ llvm::StringRef path) { Status error; - static ConstString g_dylibext(".dylib"); - static ConstString g_solibext(".so"); + static constexpr llvm::StringLiteral g_dylibext(".dylib"); + static constexpr llvm::StringLiteral g_solibext(".so"); if (!baton) return FileSystem::eEnumerateDirectoryResultQuit; diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2029,7 +2029,7 @@ // contain the note section specifying the environment to Android but the // custom extension and file name makes it highly unlikely that this will // collide with anything else. - ConstString file_extension = m_file.GetFileNameExtension(); + llvm::StringRef file_extension = m_file.GetFileNameExtension(); bool skip_oatdata_oatexec = file_extension == ".oat" || file_extension == ".odex"; diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -281,7 +281,7 @@ Status PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, const FileSpec &dst_file_spec) { // For oat file we can try to fetch additional debug info from the device - ConstString extension = module_sp->GetFileSpec().GetFileNameExtension(); + llvm::StringRef extension = module_sp->GetFileSpec().GetFileNameExtension(); if (extension != ".oat" && extension != ".odex") return Status( "Symbol file downloading only supported for oat and odex files"); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -418,8 +418,8 @@ FileSystem::EnumerateDirectoryResult PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory( void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) { - static ConstString g_sdk_suffix = ConstString(".sdk"); - static ConstString g_kdk_suffix = ConstString(".kdk"); + static constexpr llvm::StringLiteral g_sdk_suffix = ".sdk"; + static constexpr llvm::StringLiteral g_kdk_suffix = ".kdk"; PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; FileSpec file_spec(path); @@ -480,11 +480,11 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path, bool recurse) { - static ConstString g_kext_suffix = ConstString(".kext"); - static ConstString g_dsym_suffix = ConstString(".dSYM"); + static constexpr llvm::StringLiteral g_kext_suffix = ".kext"; + static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM"; FileSpec file_spec(path); - ConstString file_spec_extension = file_spec.GetFileNameExtension(); + llvm::StringRef file_spec_extension = file_spec.GetFileNameExtension(); Log *log = GetLog(LLDBLog::Platform); @@ -664,7 +664,7 @@ // /dir/dir/mach.development.t7004 bool PlatformDarwinKernel::KerneldSYMHasNoSiblingBinary( const FileSpec &kernel_dsym) { - static ConstString g_dsym_suffix = ConstString(".dSYM"); + static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM"; std::string possible_path = kernel_dsym.GetPath(); if (kernel_dsym.GetFileNameExtension() != g_dsym_suffix) return false; @@ -694,7 +694,7 @@ std::vector PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(FileSpec dsym_bundle) { std::vector results; - static ConstString g_dsym_suffix = ConstString(".dSYM"); + static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM"; if (dsym_bundle.GetFileNameExtension() != g_dsym_suffix) { return results; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -137,7 +137,7 @@ llvm::inconvertibleErrorCode()); } - ConstString module_extension = file.GetFileNameExtension(); + llvm::StringRef module_extension = file.GetFileNameExtension(); if (module_extension != ".lua") { return llvm::make_error("invalid extension", llvm::inconvertibleErrorCode()); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -306,7 +306,7 @@ // On windows, we need to manually back out of the python tree, and go into // the bin directory. This is pretty much the inverse of what ComputePythonDir // does. - if (this_file.GetFileNameExtension() == ConstString(".pyd")) { + if (this_file.GetFileNameExtension() == ".pyd") { this_file.RemoveLastPathComponent(); // _lldb.pyd or _lldb_d.pyd this_file.RemoveLastPathComponent(); // lldb llvm::StringRef libdir = LLDB_PYTHON_RELATIVE_LIBDIR; diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -399,9 +399,8 @@ Denormalize(path, m_style); } -ConstString FileSpec::GetFileNameExtension() const { - return ConstString( - llvm::sys::path::extension(m_filename.GetStringRef(), m_style)); +llvm::StringRef FileSpec::GetFileNameExtension() const { + return llvm::sys::path::extension(m_filename.GetStringRef(), m_style); } ConstString FileSpec::GetFileNameStrippingExtension() const { @@ -478,8 +477,8 @@ /// \b true if the filespec represents an implementation source /// file, \b false otherwise. bool FileSpec::IsSourceImplementationFile() const { - ConstString extension(GetFileNameExtension()); - if (!extension) + llvm::StringRef extension = GetFileNameExtension(); + if (extension.empty()) return false; static RegularExpression g_source_file_regex(llvm::StringRef( @@ -487,7 +486,7 @@ "cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][" "rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])" "$")); - return g_source_file_regex.Execute(extension.GetStringRef()); + return g_source_file_regex.Execute(extension); } bool FileSpec::IsRelative() const { diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp --- a/lldb/unittests/Utility/FileSpecTest.cpp +++ b/lldb/unittests/Utility/FileSpecTest.cpp @@ -456,7 +456,7 @@ FileSpec just_dot = PosixSpec("/tmp/bar."); EXPECT_TRUE(dylib.GetFileNameExtension() == ".dylib"); - EXPECT_TRUE(exe.GetFileNameExtension() == ConstString(nullptr)); + EXPECT_TRUE(exe.GetFileNameExtension() == llvm::StringRef()); EXPECT_TRUE(dSYM.GetFileNameExtension() == ".dSYM"); EXPECT_TRUE(just_dot.GetFileNameExtension() == "."); @@ -464,7 +464,7 @@ FileSpec win_noext = WindowsSpec("C:\\tmp\\foo"); EXPECT_TRUE(dll.GetFileNameExtension() == ".dll"); - EXPECT_TRUE(win_noext.GetFileNameExtension() == ConstString(nullptr)); + EXPECT_TRUE(win_noext.GetFileNameExtension() == llvm::StringRef()); } TEST(FileSpecTest, TestFileNameStrippingExtension) {