Skip to content

Commit 1ec362c

Browse files
committed
[SourceKit] Improve memory cost function of ASTBuildOperation
1 parent 920878e commit 1ec362c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ struct FileContent {
246246
explicit operator InputFile() const {
247247
return InputFile(Filename, IsPrimary, Buffer.get());
248248
}
249+
250+
size_t getMemoryCost() const {
251+
return sizeof(*this) + Filename.size() + Buffer->getBufferSize();
252+
}
249253
};
250254

251255
/// An \c ASTBuildOperations builds an AST. Once the AST is built, it informs
@@ -400,8 +404,12 @@ class ASTBuildOperation
400404
}
401405

402406
size_t getMemoryCost() {
403-
return sizeof(*this) + getVectorMemoryCost(FileContents) +
404-
Result.getMemoryCost();
407+
size_t Cost = sizeof(*this) + getVectorMemoryCost(FileContents) +
408+
Result.getMemoryCost();
409+
for (const FileContent &File : FileContents) {
410+
Cost += File.getMemoryCost();
411+
}
412+
return Cost;
405413
}
406414

407415
/// Schedule building this AST on the given \p Queue.

0 commit comments

Comments
 (0)