r3bl-org/r3bl-open-core

[Audit] Does TWData even need to be shared down to render op impl?

Closed this issue · 1 comments

When things were first implemented, there was a need to share cursor_position: Position to various RenderOp impls. This is because the cursor position was managed globally and there was no concept of atomic paint operations.

With the introduction of atomic RenderOps is it even necessary to do this? Can't a &mut caret_position be shared from the RenderOps down? This would simply prevent certain side effects from ever having the chance of manifesting (as they can today!).

Findings - there is no need to do this due to the requirement of the PaintRenderOp::paint() trait to modify the Position that is passed in. In other words, interior mutability is required for the Position which is used during paint operations and also possibly updated as well.

So, whether SharedTWData is passed in or Arc<Mutex<Position>> it doesn't really matter either way. There will be a performance hit due to the locking either way, so might as well leave it as is.