diff options
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r-- | flang/lib/Semantics/mod-file.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp index 5dcc198..8e95b82 100644 --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -414,36 +414,25 @@ void ModFileWriter::PutUseExtraAttr( // Collect the symbols of this scope sorted by their original order, not name. // Namelists are an exception: they are sorted after other symbols. SymbolVector CollectSymbols(const Scope &scope) { - SymbolSet symbols; // to prevent duplicates SymbolVector sorted; SymbolVector namelist; - SymbolVector common; - sorted.reserve(scope.size() + scope.commonBlocks().size()); - for (const auto &pair : scope) { - const Symbol &symbol{*pair.second}; - if (!symbol.test(Symbol::Flag::ParentComp)) { - if (symbols.insert(symbol).second) { - if (symbol.has<NamelistDetails>()) { - namelist.push_back(symbol); - } else { - sorted.push_back(symbol); - } + std::size_t commonSize{scope.commonBlocks().size()}; + auto symbols{scope.GetSymbols()}; + sorted.reserve(symbols.size() + commonSize); + for (SymbolRef symbol : symbols) { + if (!symbol->test(Symbol::Flag::ParentComp)) { + if (symbol->has<NamelistDetails>()) { + namelist.push_back(symbol); + } else { + sorted.push_back(symbol); } } } + sorted.insert(sorted.end(), namelist.begin(), namelist.end()); for (const auto &pair : scope.commonBlocks()) { - const Symbol &symbol{*pair.second}; - if (symbols.insert(symbol).second) { - common.push_back(symbol); - } + sorted.push_back(*pair.second); } - // sort normal symbols, then namelists, then common blocks: - auto cursor{sorted.begin()}; - std::sort(cursor, sorted.end()); - cursor = sorted.insert(sorted.end(), namelist.begin(), namelist.end()); - std::sort(cursor, sorted.end()); - cursor = sorted.insert(sorted.end(), common.begin(), common.end()); - std::sort(cursor, sorted.end()); + std::sort(sorted.end() - commonSize, sorted.end()); return sorted; } |