mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[NFC] Avoid repeatedly instantiating std::function
This commit is contained in:
@@ -308,21 +308,22 @@ bool tryCheckedCastBrJumpThreading(
|
||||
/// A structure containing callbacks that are called when an instruction is
|
||||
/// removed or added.
|
||||
struct InstModCallbacks {
|
||||
std::function<void(SILInstruction *)> deleteInst = [](SILInstruction *inst) {
|
||||
inst->eraseFromParent();
|
||||
};
|
||||
std::function<void(SILInstruction *)> createdNewInst = [](SILInstruction *) {
|
||||
};
|
||||
std::function<void(SILValue, SILValue)> replaceValueUsesWith =
|
||||
[](SILValue oldValue, SILValue newValue) {
|
||||
oldValue->replaceAllUsesWith(newValue);
|
||||
};
|
||||
static const std::function<void(SILInstruction *)> defaultDeleteInst;
|
||||
static const std::function<void(SILInstruction *)> defaultCreatedNewInst;
|
||||
static const std::function<void(SILValue, SILValue)> defaultReplaceValueUsesWith;
|
||||
static const std::function<void(SingleValueInstruction *, SILValue)>
|
||||
defaultEraseAndRAUWSingleValueInst;
|
||||
|
||||
std::function<void(SILInstruction *)> deleteInst =
|
||||
InstModCallbacks::defaultDeleteInst;
|
||||
std::function<void(SILInstruction *)> createdNewInst =
|
||||
InstModCallbacks::defaultCreatedNewInst;
|
||||
std::function<void(SILValue, SILValue)>
|
||||
replaceValueUsesWith =
|
||||
InstModCallbacks::defaultReplaceValueUsesWith;
|
||||
std::function<void(SingleValueInstruction *, SILValue)>
|
||||
eraseAndRAUWSingleValueInst =
|
||||
[](SingleValueInstruction *i, SILValue newValue) {
|
||||
i->replaceAllUsesWith(newValue);
|
||||
i->eraseFromParent();
|
||||
};
|
||||
InstModCallbacks::defaultEraseAndRAUWSingleValueInst;
|
||||
|
||||
InstModCallbacks(decltype(deleteInst) deleteInst,
|
||||
decltype(createdNewInst) createdNewInst,
|
||||
@@ -330,10 +331,7 @@ struct InstModCallbacks {
|
||||
: deleteInst(deleteInst), createdNewInst(createdNewInst),
|
||||
replaceValueUsesWith(replaceValueUsesWith),
|
||||
eraseAndRAUWSingleValueInst(
|
||||
[](SingleValueInstruction *i, SILValue newValue) {
|
||||
i->replaceAllUsesWith(newValue);
|
||||
i->eraseFromParent();
|
||||
}) {}
|
||||
InstModCallbacks::defaultEraseAndRAUWSingleValueInst) {}
|
||||
|
||||
InstModCallbacks(
|
||||
decltype(deleteInst) deleteInst, decltype(createdNewInst) createdNewInst,
|
||||
|
||||
Reference in New Issue
Block a user