Skip to content

[ObjCopy] Use StringRef::starts_with (NFC) #139408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 10, 2025

@llvm/pr-subscribers-llvm-binary-utilities

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/139408.diff

1 Files Affected:

  • (modified) llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp (+1-2)
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 935f89ad76440..f810bbf639300 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -352,8 +352,7 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
       Sym.Name = std::string(I->getValue());
 
     if (!Config.SymbolsPrefixRemove.empty() && Sym.Type != STT_SECTION)
-      if (Sym.Name.compare(0, Config.SymbolsPrefixRemove.size(),
-                           Config.SymbolsPrefixRemove) == 0)
+      if (StringRef(Sym.Name).starts_with(Config.SymbolsPrefixRemove))
         Sym.Name = Sym.Name.substr(Config.SymbolsPrefixRemove.size());
 
     if (!Config.SymbolsPrefix.empty() && Sym.Type != STT_SECTION)

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use consume_front

@kazutakahirata
Copy link
Contributor Author

@MaskRay

Can use consume_front

Yes, I've thought about, but I wasn't sure if the use of a temporary variable is elegant. Thoughts?

      StringRef Tmp = Sym.Name;
      if (Tmp.consumeFront(Config.SymbolsPrefixRemove))
        Sym.Name = Tmp;

@kazutakahirata kazutakahirata merged commit d4e730f into llvm:main May 10, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_StringRef_starts_with_llvm_ObjCopy branch May 10, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants