Share SubClause
s across many Sub
s
#112
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ISSUE NUMBER - PULL_REQUEST_TITLE
None
Description
I had noticed that for popups (and likely some other cases) it is quite common to have something along the lines of
no_popups_mounted_clause
for a bunch of global events, but each will need their own memory allocation, even though their content is the same. (Real example code)This PR allows to share SubClauses by putting them in a
Arc
(as subs are never modified, only dropped) to lessen memory usage.This still allows the old way of passing in
SubClause
s toSub::new
directly, so this is not a breaking change.(it is also not a breaking change due to
SubClause
's fields not being public).I know this will likely not have much memory or speed, but it is still some and it is a easy change.
Additionally also derive
Clone
onSubClause
as it is possible due to all involved types supporting it.Alternative
As a alternative, it could also be possible to modify
Sub
/Subscription
to have aVec
ofEventClause
, though that would require a bit more code changes than this PR.Type of change
Please select relevant options.
Checklist
cargo fmt
cargo clippy
and reports no warningscfg target_os
)