Skip to content

Commit

Permalink
[llvm-readobj] Simplify startswith+drop_front pattern with consume_fr…
Browse files Browse the repository at this point in the history
…ont. NFC
  • Loading branch information
MaskRay committed Jun 24, 2022
1 parent c579ab5 commit 124d9fc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Expand Up @@ -1423,12 +1423,12 @@ static std::string getGNUPtType(unsigned Arch, unsigned Type) {
return std::string("<unknown>: ") + to_string(format_hex(Type, 1));

// E.g. "PT_ARM_EXIDX" -> "EXIDX".
if (Seg.startswith("PT_ARM_"))
return Seg.drop_front(7).str();
if (Seg.consume_front("PT_ARM_"))
return Seg.str();

// E.g. "PT_MIPS_REGINFO" -> "REGINFO".
if (Seg.startswith("PT_MIPS_"))
return Seg.drop_front(8).str();
if (Seg.consume_front("PT_MIPS_"))
return Seg.str();

// E.g. "PT_LOAD" -> "LOAD".
assert(Seg.startswith("PT_"));
Expand Down Expand Up @@ -3641,18 +3641,18 @@ static std::string getSectionTypeString(unsigned Machine, unsigned Type) {
StringRef Name = getELFSectionTypeName(Machine, Type);

// Handle SHT_GNU_* type names.
if (Name.startswith("SHT_GNU_")) {
if (Name == "SHT_GNU_HASH")
if (Name.consume_front("SHT_GNU_")) {
if (Name == "HASH")
return "GNU_HASH";
// E.g. SHT_GNU_verneed -> VERNEED.
return Name.drop_front(8).upper();
return Name.upper();
}

if (Name == "SHT_SYMTAB_SHNDX")
return "SYMTAB SECTION INDICES";

if (Name.startswith("SHT_"))
return Name.drop_front(4).str();
if (Name.consume_front("SHT_"))
return Name.str();
return getSectionTypeOffsetString(Type);
}

Expand Down

0 comments on commit 124d9fc

Please sign in to comment.