Skip to content

Commit c6f033d

Browse files
committed
[Serialization] Use existing logic to print a hierarchical module name
No intended functionality change.
1 parent 12fc353 commit c6f033d

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
193193

194194
/// This is a convenience function that writes the entire name, in forward
195195
/// order, to \p out.
196-
void printForward(raw_ostream &out) const;
196+
void printForward(raw_ostream &out, StringRef delim = ".") const;
197197
};
198198

199199
private:

lib/AST/Module.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,11 +1200,12 @@ ModuleDecl::ReverseFullNameIterator::operator++() {
12001200
}
12011201

12021202
void
1203-
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out) const {
1203+
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out,
1204+
StringRef delim) const {
12041205
SmallVector<StringRef, 8> elements(*this, {});
12051206
swift::interleave(swift::reversed(elements),
12061207
[&out](StringRef next) { out << next; },
1207-
[&out] { out << '.'; });
1208+
[&out, delim] { out << delim; });
12081209
}
12091210

12101211
void

lib/Serialization/Serialization.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -993,23 +993,19 @@ void Serializer::writeHeader(const SerializationOptions &options) {
993993
}
994994
}
995995

996-
using ImportPathBlob = llvm::SmallString<64>;
997996
static void flattenImportPath(const ModuleDecl::ImportedModule &import,
998-
ImportPathBlob &out) {
999-
SmallVector<StringRef, 4> reverseSubmoduleNames(
1000-
import.second->getReverseFullModuleName(), {});
1001-
1002-
interleave(reverseSubmoduleNames.rbegin(), reverseSubmoduleNames.rend(),
1003-
[&out](StringRef next) { out.append(next); },
1004-
[&out] { out.push_back('\0'); });
997+
SmallVectorImpl<char> &out) {
998+
llvm::raw_svector_ostream outStream(out);
999+
import.second->getReverseFullModuleName().printForward(outStream,
1000+
StringRef("\0", 1));
10051001

10061002
if (import.first.empty())
10071003
return;
10081004

1009-
out.push_back('\0');
1005+
outStream << '\0';
10101006
assert(import.first.size() == 1 && "can only handle top-level decl imports");
10111007
auto accessPathElem = import.first.front();
1012-
out.append(accessPathElem.first.str());
1008+
outStream << accessPathElem.first.str();
10131009
}
10141010

10151011
uint64_t getRawModTimeOrHash(const SerializationOptions::FileDependency &dep) {
@@ -1122,7 +1118,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
11221118
continue;
11231119
}
11241120

1125-
ImportPathBlob importPath;
1121+
SmallString<64> importPath;
11261122
flattenImportPath(import, importPath);
11271123

11281124
serialization::ImportControl stableImportControl;

0 commit comments

Comments
 (0)