Author: Alex Langford Date: 2023-04-26T15:56:29-07:00 New Revision: 6fcdfc378c2f926ed5a175326fe799844c1c80b2
URL: https://github.com/llvm/llvm-project/commit/6fcdfc378c2f926ed5a175326fe799844c1c80b2 DIFF: https://github.com/llvm/llvm-project/commit/6fcdfc378c2f926ed5a175326fe799844c1c80b2.diff LOG: [lldb] Change return type of FileSpec::GetFileNameExtension These don't really need to be in ConstStrings. It's nice that comparing ConstStrings is fast (just a pointer comparison) but the cost of creating the ConstString usually already includes the cost of doing a StringRef comparison anyway, so this is just extra work and extra memory consumption for basically no benefit. Differential Revision: https://reviews.llvm.org/D149300 Added: Modified: lldb/include/lldb/Utility/FileSpec.h lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Core/Debugger.cpp lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Utility/FileSpec.cpp lldb/unittests/Utility/FileSpecTest.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index 08fd1017eccd2..3238bacacb929 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -329,8 +329,8 @@ class FileSpec { /// 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 index aecdf595ee5b5..6d63b306d42a1 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -2163,7 +2163,7 @@ class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed { 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 index 401561e8e06d6..581b29e6bc1ef 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -607,8 +607,8 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, 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 index 0c39a4f68e878..2443d83a3cb3a 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2029,7 +2029,7 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id, // 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 index 1afce4f41a823..64c1d1e48a9ef 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -281,7 +281,7 @@ uint32_t PlatformAndroid::GetSdkVersion() { 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 index 784381ada66e1..2e44985542150 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -418,8 +418,8 @@ void PlatformDarwinKernel::AddSDKSubdirsToSearchPaths(const std::string &dir) { 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 @@ FileSystem::EnumerateDirectoryResult 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 @@ bool PlatformDarwinKernel::KernelHasdSYMSibling(const FileSpec &kernel_binary) { // /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 @@ bool PlatformDarwinKernel::KerneldSYMHasNoSiblingBinary( std::vector<FileSpec> PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(FileSpec dsym_bundle) { std::vector<FileSpec> 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 index b82a2647e9a08..852bb3bb14c6c 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -137,7 +137,7 @@ llvm::Error Lua::LoadModule(llvm::StringRef filename) { llvm::inconvertibleErrorCode()); } - ConstString module_extension = file.GetFileNameExtension(); + llvm::StringRef module_extension = file.GetFileNameExtension(); if (module_extension != ".lua") { return llvm::make_error<llvm::StringError>("invalid extension", llvm::inconvertibleErrorCode()); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 6472a9301ed6e..3af3c87dab338 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -306,7 +306,7 @@ void ScriptInterpreterPython::SharedLibraryDirectoryHelper( // 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 index 939f967d7a91b..5ab8e8200a419 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -399,9 +399,8 @@ void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path, 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 @@ bool FileSpec::RemoveLastPathComponent() { /// \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 @@ bool FileSpec::IsSourceImplementationFile() const { "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 index 96f19953c3b74..ffd3d343dc188 100644 --- a/lldb/unittests/Utility/FileSpecTest.cpp +++ b/lldb/unittests/Utility/FileSpecTest.cpp @@ -456,7 +456,7 @@ TEST(FileSpecTest, TestFileNameExtensions) { 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 @@ TEST(FileSpecTest, TestFileNameExtensions) { 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) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits