@@ -169,31 +169,33 @@ class UpdatingInstructionIteratorRegistry {
169
169
SmallVector<UpdatingInstructionIterator *, 4 > forwardIterators;
170
170
SmallVector<UpdatingReverseInstructionIterator *, 4 > reverseIterators;
171
171
172
+ std::function<void (SILInstruction *)> chainedDelete;
173
+ std::function<void (SILInstruction *)> chainedNew;
174
+
172
175
// / Callbacks used when adding/deleting instructions.
173
176
InstModCallbacks callbacks;
174
177
175
- public:
176
- UpdatingInstructionIteratorRegistry (
177
- InstModCallbacks chainedCallbacks = InstModCallbacks()) {
178
- rechainCallbacks (chainedCallbacks);
179
- }
180
-
181
- // The callbacks capture 'this'. So copying is invalid.
182
- UpdatingInstructionIteratorRegistry (
183
- const UpdatingInstructionIteratorRegistry &) = delete ;
184
-
185
- UpdatingInstructionIteratorRegistry &
186
- operator =(const UpdatingInstructionIteratorRegistry &) = delete ;
187
178
188
- InstModCallbacks &getCallbacks () { return callbacks; }
179
+ public:
180
+ UpdatingInstructionIteratorRegistry () :
181
+ callbacks (InstModCallbacks()
182
+ .onDelete([this ](SILInstruction *toDelete) {
183
+ notifyDelete (toDelete);
184
+ toDelete->eraseFromParent ();
185
+ })
186
+ .onCreateNewInst(
187
+ [this ](SILInstruction *newlyCreatedInst) {
188
+ notifyNew (newlyCreatedInst);
189
+ }))
190
+ {}
189
191
190
- void rechainCallbacks (InstModCallbacks chainedCallbacks) {
192
+ UpdatingInstructionIteratorRegistry (InstModCallbacks && chainedCallbacks) :
191
193
// Copy the two std::functions that we need. The rest of the callbacks are
192
194
// copied implicitly by assignment.
193
- auto chainedDelete = chainedCallbacks.deleteInstFunc ;
194
- auto chainedNew = chainedCallbacks.createdNewInstFunc ;
195
- callbacks = chainedCallbacks
196
- .onDelete ([this , chainedDelete ](SILInstruction *toDelete) {
195
+ chainedDelete (std::move( chainedCallbacks.deleteInstFunc)),
196
+ chainedNew (std::move( chainedCallbacks.createdNewInstFunc)),
197
+ callbacks (std::move( chainedCallbacks
198
+ .onDelete([this ](SILInstruction *toDelete) {
197
199
notifyDelete (toDelete);
198
200
if (chainedDelete) {
199
201
chainedDelete (toDelete);
@@ -202,13 +204,22 @@ class UpdatingInstructionIteratorRegistry {
202
204
toDelete->eraseFromParent ();
203
205
})
204
206
.onCreateNewInst(
205
- [this , chainedNew ](SILInstruction *newlyCreatedInst) {
207
+ [this ](SILInstruction *newlyCreatedInst) {
206
208
notifyNew (newlyCreatedInst);
207
209
if (chainedNew) {
208
210
chainedNew (newlyCreatedInst);
209
211
}
210
- });
211
- }
212
+ })))
213
+ {}
214
+
215
+ // The callbacks capture 'this'. So copying is invalid.
216
+ UpdatingInstructionIteratorRegistry (
217
+ const UpdatingInstructionIteratorRegistry &) = delete ;
218
+
219
+ UpdatingInstructionIteratorRegistry &
220
+ operator =(const UpdatingInstructionIteratorRegistry &) = delete ;
221
+
222
+ InstModCallbacks &getCallbacks () { return callbacks; }
212
223
213
224
void registerIterator (UpdatingInstructionIterator *i) {
214
225
forwardIterators.push_back (i);
0 commit comments