[llvm-readobj] Check ELFType value first when checking for OpenBSD notes.
authorFrederic Cambus <fred@statdns.com>
Mon, 20 Dec 2021 15:22:01 +0000 (16:22 +0100)
committerFrederic Cambus <fred@statdns.com>
Mon, 20 Dec 2021 15:32:02 +0000 (16:32 +0100)
Checking ELFType == ELF::ET_CORE first skips string comparison for the
majority of cases.

Suggested by Fangrui Song in D114635 for a similar construct.

llvm/tools/llvm-readobj/ELFDumper.cpp

index 2f64b07..9d9c222 100644 (file)
@@ -5492,7 +5492,7 @@ StringRef getNoteTypeName(const typename ELFT::Note &Note, unsigned ELFType) {
       return Result;
     return FindNote(CoreNoteTypes);
   }
-  if (Name.startswith("OpenBSD") && ELFType == ELF::ET_CORE) {
+  if (ELFType == ELF::ET_CORE && Name.startswith("OpenBSD")) {
     // OpenBSD also places the generic core notes in the OpenBSD namespace.
     StringRef Result = FindNote(OpenBSDCoreNoteTypes);
     if (!Result.empty())