diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index a1112eaa538..f920eb09158 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -193,7 +193,7 @@ public: /// This is a convenience function that writes the entire name, in forward /// order, to \p out. - void printForward(raw_ostream &out) const; + void printForward(raw_ostream &out, StringRef delim = ".") const; }; private: diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 094ebaa1089..879ac6a26ec 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -1200,11 +1200,12 @@ ModuleDecl::ReverseFullNameIterator::operator++() { } void -ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out) const { +ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out, + StringRef delim) const { SmallVector elements(*this, {}); swift::interleave(swift::reversed(elements), [&out](StringRef next) { out << next; }, - [&out] { out << '.'; }); + [&out, delim] { out << delim; }); } void diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 2f021abfe29..1179624d370 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -993,23 +993,19 @@ void Serializer::writeHeader(const SerializationOptions &options) { } } -using ImportPathBlob = llvm::SmallString<64>; static void flattenImportPath(const ModuleDecl::ImportedModule &import, - ImportPathBlob &out) { - SmallVector reverseSubmoduleNames( - import.second->getReverseFullModuleName(), {}); - - interleave(reverseSubmoduleNames.rbegin(), reverseSubmoduleNames.rend(), - [&out](StringRef next) { out.append(next); }, - [&out] { out.push_back('\0'); }); + SmallVectorImpl &out) { + llvm::raw_svector_ostream outStream(out); + import.second->getReverseFullModuleName().printForward(outStream, + StringRef("\0", 1)); if (import.first.empty()) return; - out.push_back('\0'); + outStream << '\0'; assert(import.first.size() == 1 && "can only handle top-level decl imports"); auto accessPathElem = import.first.front(); - out.append(accessPathElem.first.str()); + outStream << accessPathElem.first.str(); } uint64_t getRawModTimeOrHash(const SerializationOptions::FileDependency &dep) { @@ -1122,7 +1118,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) { continue; } - ImportPathBlob importPath; + SmallString<64> importPath; flattenImportPath(import, importPath); serialization::ImportControl stableImportControl;