Skip to content

Commit edd5dfc

Browse files
committed
[Support] Replace function with function_ref in writeFileAtomically. NFC
Summary: The latter is slightly more efficient and communicates the intent of the API: writeFileAtomically does not own or copy the callback, it merely calls it at some point. Reviewers: jkorous Reviewed By: jkorous Subscribers: hiraditya, dexonsmith, jfb, llvm-commits, cfe-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67584 llvm-svn: 372201
1 parent 93e1f73 commit edd5dfc

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/include/llvm/Support/FileUtilities.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_SUPPORT_FILEUTILITIES_H
1515
#define LLVM_SUPPORT_FILEUTILITIES_H
1616

17+
#include "llvm/ADT/STLExtras.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/Support/Errc.h"
1920
#include "llvm/Support/ErrorHandling.h"
@@ -107,9 +108,9 @@ namespace llvm {
107108
llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
108109
StringRef Buffer);
109110

110-
llvm::Error
111-
writeFileAtomically(StringRef TempPathModel, StringRef FinalPath,
112-
std::function<llvm::Error(llvm::raw_ostream &)> Writer);
111+
llvm::Error writeFileAtomically(
112+
StringRef TempPathModel, StringRef FinalPath,
113+
llvm::function_ref<llvm::Error(llvm::raw_ostream &)> Writer);
113114
} // End llvm namespace
114115

115116
#endif

llvm/lib/Support/FileUtilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ llvm::Error llvm::writeFileAtomically(StringRef TempPathModel,
296296

297297
llvm::Error llvm::writeFileAtomically(
298298
StringRef TempPathModel, StringRef FinalPath,
299-
std::function<llvm::Error(llvm::raw_ostream &)> Writer) {
299+
llvm::function_ref<llvm::Error(llvm::raw_ostream &)> Writer) {
300300
SmallString<128> GeneratedUniqPath;
301301
int TempFD;
302302
if (sys::fs::createUniqueFile(TempPathModel.str(), TempFD,

0 commit comments

Comments
 (0)