@@ -145,10 +145,10 @@ struct lazy_duplex_apply_signal
145
145
{
146
146
return arg_.ready_to_write ();
147
147
}
148
- void
148
+ id_interface const &
149
149
write (Result value) const
150
150
{
151
- arg_.write (reverse_ (std::move (value)));
151
+ return arg_.write (reverse_ (std::move (value)));
152
152
}
153
153
154
154
private:
@@ -429,24 +429,29 @@ struct duplex_apply_signal : signal<
429
429
{
430
430
return input_.ready_to_write ();
431
431
}
432
- void
432
+ id_interface const &
433
433
write (Value value) const
434
434
{
435
- input_.write (reverse_ (value));
436
- // This is sort of hackish, but the idea here is that if we do nothing
437
- // right now, on the next refresh, we're going to detect that the input
438
- // signal has changed, and then apply the forward mapping to convert
439
- // that value back to the one we're writing right now, which is
440
- // obviously wasted effort.
441
- // To attempt to avoid this, we capture the value ID of the input after
442
- // writing to it in the hopes that it has already changed. (That is the
443
- // case for some signal types, but not all.)
444
- // To do this properly, we should probably allow signal write()
445
- // functions to return a new value ID.
446
- data_->input_id .capture (input_.value_id ());
447
- ++data_->result .version ;
448
- data_->result .value = std::move (value);
449
- data_->result .status = apply_status::READY;
435
+ id_interface const & new_value_id = input_.write (reverse_ (value));
436
+ // If we stop here, then on the next refresh, we're going to detect
437
+ // that the input signal has changed (to what we just set it to), and
438
+ // then apply the forward mapping to convert that value back to the one
439
+ // we just received, which is obviously wasted effort. To avoid this,
440
+ // we need to just record the new value as our ouput and record the
441
+ // input's new value ID to go along with it. (This is only possible
442
+ // though if the input signal actually supplies its new value ID.)
443
+ if (new_value_id != null_id)
444
+ {
445
+ data_->input_id .capture (new_value_id);
446
+ ++data_->result .version ;
447
+ data_->result .value = std::move (value);
448
+ data_->result .status = apply_status::READY;
449
+ return this ->value_id ();
450
+ }
451
+ else
452
+ {
453
+ return null_id;
454
+ }
450
455
}
451
456
452
457
private:
0 commit comments