@@ -249,17 +249,16 @@ class proof_trace_callback_writer : public proof_trace_writer {
249
249
char const *location;
250
250
std::vector<kore_term_construction> arguments;
251
251
std::optional<kore_term_construction> result;
252
-
253
- call_event_construction (
254
- char const *hook_name, char const *symbol_name, char const *location)
255
- : hook_name(hook_name)
256
- , symbol_name(symbol_name)
257
- , location(location) { }
258
-
259
- call_event_construction (char const *symbol_name, char const *location)
260
- : hook_name(nullptr )
261
- , symbol_name(symbol_name)
262
- , location(location) { }
252
+ //
253
+ // To avoid a heap allocation and deallocation for arguments on each event we reuse it.
254
+ //
255
+ void reinitialize (char const *h_name, char const *s_name, char const *loc) {
256
+ hook_name = h_name;
257
+ symbol_name = s_name;
258
+ location = loc;
259
+ arguments.clear ();
260
+ result.reset ();
261
+ }
263
262
};
264
263
265
264
struct rewrite_event_construction {
@@ -270,20 +269,23 @@ class proof_trace_callback_writer : public proof_trace_writer {
270
269
uint64_t arity;
271
270
size_t pos;
272
271
subst_t substitution;
273
-
274
- rewrite_event_construction (uint64_t ordinal, uint64_t arity)
275
- : ordinal(ordinal)
276
- , arity(arity)
277
- , pos(0 ) {
272
+ //
273
+ // To avoid a heap allocation and deallocation for substitution on each event we reuse it.
274
+ //
275
+ void reinitialize (uint64_t ord, uint64_t arty) {
276
+ ordinal = ord;
277
+ arity = arty;
278
+ pos = 0 ;
278
279
substitution.resize (arity);
279
280
}
280
281
};
281
282
282
283
private:
283
- std::optional<call_event_construction> current_call_event_;
284
-
285
- std::optional<rewrite_event_construction> current_rewrite_event_{
286
- std::nullopt};
284
+ //
285
+ // These structs get reused.
286
+ //
287
+ call_event_construction current_call_event_;
288
+ rewrite_event_construction current_rewrite_event_;
287
289
288
290
bool rewrite_callback_pending_;
289
291
@@ -315,25 +317,23 @@ class proof_trace_callback_writer : public proof_trace_writer {
315
317
void hook_event_pre (
316
318
char const *name, char const *pattern,
317
319
char const *location_stack) override {
318
- current_call_event_.reset ();
319
- current_call_event_.emplace (name, pattern, location_stack);
320
+ current_call_event_.reinitialize (name, pattern, location_stack);
320
321
}
321
322
322
323
void hook_event_post (
323
324
void *hook_result, uint64_t block_header, uint64_t bits) override {
324
- current_call_event_-> result .emplace (hook_result, block_header, bits);
325
- hook_event_callback (current_call_event_. value () );
325
+ current_call_event_. result .emplace (hook_result, block_header, bits);
326
+ hook_event_callback (current_call_event_);
326
327
}
327
328
328
329
void argument (void *arg, uint64_t block_header, uint64_t bits) override {
329
- current_call_event_-> arguments .emplace_back (arg, block_header, bits);
330
+ current_call_event_. arguments .emplace_back (arg, block_header, bits);
330
331
}
331
332
332
333
void rewrite_event_pre (uint64_t ordinal, uint64_t arity) override {
333
- current_rewrite_event_.reset ();
334
- current_rewrite_event_.emplace (ordinal, arity);
334
+ current_rewrite_event_.reinitialize (ordinal, arity);
335
335
if (arity == 0 ) {
336
- rewrite_event_callback (current_rewrite_event_. value () );
336
+ rewrite_event_callback (current_rewrite_event_);
337
337
} else {
338
338
rewrite_callback_pending_ = true ;
339
339
}
@@ -342,18 +342,18 @@ class proof_trace_callback_writer : public proof_trace_writer {
342
342
void variable (
343
343
char const *name, void *var, uint64_t block_header,
344
344
uint64_t bits) override {
345
- auto &p = current_rewrite_event_-> substitution [current_rewrite_event_-> pos ];
345
+ auto &p = current_rewrite_event_. substitution [current_rewrite_event_. pos ];
346
346
p.first = name;
347
347
p.second .subject = var;
348
348
p.second .block_header = block_header;
349
349
p.second .bits = bits;
350
- size_t new_pos = ++current_rewrite_event_-> pos ;
351
- if (new_pos == current_rewrite_event_-> arity ) {
350
+ size_t new_pos = ++current_rewrite_event_. pos ;
351
+ if (new_pos == current_rewrite_event_. arity ) {
352
352
if (rewrite_callback_pending_) {
353
- rewrite_event_callback (current_rewrite_event_. value () );
353
+ rewrite_event_callback (current_rewrite_event_);
354
354
rewrite_callback_pending_ = false ;
355
355
} else {
356
- side_condition_event_callback (current_rewrite_event_. value () );
356
+ side_condition_event_callback (current_rewrite_event_);
357
357
}
358
358
}
359
359
}
@@ -366,19 +366,17 @@ class proof_trace_callback_writer : public proof_trace_writer {
366
366
367
367
void
368
368
function_event_pre (char const *name, char const *location_stack) override {
369
- current_call_event_.reset ();
370
- current_call_event_.emplace (name, location_stack);
369
+ current_call_event_.reinitialize (nullptr , name, location_stack);
371
370
}
372
371
373
372
void function_event_post () override {
374
- function_event_callback (current_call_event_. value () );
373
+ function_event_callback (current_call_event_);
375
374
}
376
375
377
376
void side_condition_event_pre (uint64_t ordinal, uint64_t arity) override {
378
- current_rewrite_event_.reset ();
379
- current_rewrite_event_.emplace (ordinal, arity);
377
+ current_rewrite_event_.reinitialize (ordinal, arity);
380
378
if (arity == 0 ) {
381
- side_condition_event_callback (current_rewrite_event_. value () );
379
+ side_condition_event_callback (current_rewrite_event_);
382
380
}
383
381
}
384
382
0 commit comments