Skip to content

Commit e83afbe

Browse files
committed
[ELF] Remove unneeded sec->file check
1 parent 8387cbd commit e83afbe

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,33 +402,30 @@ void LinkerScript::assignSymbol(SymbolAssignment *cmd, bool inSec) {
402402
cmd->sym->type = v.type;
403403
}
404404

405-
static inline StringRef getFilename(const InputFile *file) {
406-
return file ? file->getNameForScript() : StringRef();
407-
}
408-
409-
bool InputSectionDescription::matchesFile(const InputFile *file) const {
405+
bool InputSectionDescription::matchesFile(const InputFile &file) const {
410406
if (filePat.isTrivialMatchAll())
411407
return true;
412408

413-
if (!matchesFileCache || matchesFileCache->first != file)
414-
matchesFileCache.emplace(file, filePat.match(getFilename(file)));
409+
if (!matchesFileCache || matchesFileCache->first != &file)
410+
matchesFileCache.emplace(&file, filePat.match(file.getNameForScript()));
415411

416412
return matchesFileCache->second;
417413
}
418414

419-
bool SectionPattern::excludesFile(const InputFile *file) const {
415+
bool SectionPattern::excludesFile(const InputFile &file) const {
420416
if (excludedFilePat.empty())
421417
return false;
422418

423-
if (!excludesFileCache || excludesFileCache->first != file)
424-
excludesFileCache.emplace(file, excludedFilePat.match(getFilename(file)));
419+
if (!excludesFileCache || excludesFileCache->first != &file)
420+
excludesFileCache.emplace(&file,
421+
excludedFilePat.match(file.getNameForScript()));
425422

426423
return excludesFileCache->second;
427424
}
428425

429426
bool LinkerScript::shouldKeep(InputSectionBase *s) {
430427
for (InputSectionDescription *id : keptSections)
431-
if (id->matchesFile(s->file))
428+
if (id->matchesFile(*s->file))
432429
for (SectionPattern &p : id->sectionPatterns)
433430
if (p.sectionPat.match(s->name) &&
434431
(s->flags & id->withFlags) == id->withFlags &&
@@ -557,7 +554,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
557554
if (!pat.sectionPat.match(sec->name))
558555
continue;
559556

560-
if (!cmd->matchesFile(sec->file) || pat.excludesFile(sec->file) ||
557+
if (!cmd->matchesFile(*sec->file) || pat.excludesFile(*sec->file) ||
561558
sec->parent == &outCmd || !flagsMatch(sec))
562559
continue;
563560

lld/ELF/LinkerScript.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class SectionPattern {
186186
sortOuter(SortSectionPolicy::Default),
187187
sortInner(SortSectionPolicy::Default) {}
188188

189-
bool excludesFile(const InputFile *file) const;
189+
bool excludesFile(const InputFile &file) const;
190190

191191
StringMatcher sectionPat;
192192
SortSectionPolicy sortOuter;
@@ -212,7 +212,7 @@ class InputSectionDescription : public SectionCommand {
212212
return c->kind == InputSectionKind;
213213
}
214214

215-
bool matchesFile(const InputFile *file) const;
215+
bool matchesFile(const InputFile &file) const;
216216

217217
// Input sections that matches at least one of SectionPatterns
218218
// will be associated with this InputSectionDescription.

0 commit comments

Comments
 (0)