Skip to content

Commit fba8b10

Browse files
authored
Merge pull request #75115 from rintaro/basic-ondiscbuffer-cache
[Basic] Don't rewrite source buffer copy multiple times
2 parents 8b618c6 + 90c2975 commit fba8b10

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class GeneratedSourceInfo {
7575

7676
/// The name of the source file on disk that was created to hold the
7777
/// contents of this file for external clients.
78-
StringRef onDiskBufferCopyFileName = StringRef();
78+
mutable StringRef onDiskBufferCopyFileName = StringRef();
7979

8080
/// Contains the ancestors of this source buffer, starting with the root source
8181
/// buffer and ending at this source buffer.
@@ -213,8 +213,7 @@ class SourceManager {
213213
bool hasGeneratedSourceInfo(unsigned bufferID);
214214

215215
/// Retrieve the generated source information for the given buffer.
216-
std::optional<GeneratedSourceInfo>
217-
getGeneratedSourceInfo(unsigned bufferID) const;
216+
const GeneratedSourceInfo *getGeneratedSourceInfo(unsigned bufferID) const;
218217

219218
/// Retrieve the list of ancestors of the given source buffer, starting with
220219
/// the root buffer and proceding to the given buffer ID at the end.

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ ModuleDecl::getOriginalLocation(SourceLoc loc) const {
907907

908908
SourceLoc startLoc = loc;
909909
unsigned startBufferID = bufferID;
910-
while (std::optional<GeneratedSourceInfo> info =
910+
while (const GeneratedSourceInfo *info =
911911
SM.getGeneratedSourceInfo(bufferID)) {
912912
switch (info->kind) {
913913
#define MACRO_ROLE(Name, Description) \

lib/Basic/SourceLoc.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ StringRef SourceManager::getIdentifierForBuffer(
288288
// If this is generated source code, and we're supposed to force it to disk
289289
// so external clients can see it, do so now.
290290
if (ForceGeneratedSourceToDisk) {
291-
if (auto generatedInfo = getGeneratedSourceInfo(bufferID)) {
291+
if (const GeneratedSourceInfo *generatedInfo =
292+
getGeneratedSourceInfo(bufferID)) {
292293
// We only care about macros, so skip everything else.
293294
if (generatedInfo->kind == GeneratedSourceInfo::ReplacedFunctionBody ||
294295
generatedInfo->kind == GeneratedSourceInfo::PrettyPrinted ||
@@ -403,12 +404,12 @@ bool SourceManager::hasGeneratedSourceInfo(unsigned bufferID) {
403404
return GeneratedSourceInfos.count(bufferID);
404405
}
405406

406-
std::optional<GeneratedSourceInfo>
407+
const GeneratedSourceInfo *
407408
SourceManager::getGeneratedSourceInfo(unsigned bufferID) const {
408409
auto known = GeneratedSourceInfos.find(bufferID);
409410
if (known == GeneratedSourceInfos.end())
410-
return std::nullopt;
411-
return known->second;
411+
return nullptr;
412+
return &known->second;
412413
}
413414

414415
namespace {

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static DeclContext *getInnermostFunctionContext(DeclContext *DC) {
285285
}
286286

287287
/// Return location of the macro expansion and the macro name.
288-
static MacroInfo getMacroInfo(GeneratedSourceInfo &Info,
288+
static MacroInfo getMacroInfo(const GeneratedSourceInfo &Info,
289289
DeclContext *FunctionDC) {
290290
MacroInfo Result(Info.generatedSourceRange.getStart(),
291291
Info.originalSourceRange.getStart());

0 commit comments

Comments
 (0)