Use pointers to refer to elements and regulators #84
No reviewers
Labels
No labels
bug
design
duplicate
enhancement
maintenance
prospective
question
regression
stub
todo
ui
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: StudioInfinity/dyna3#84
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Vectornaut/dyna3:use-pointers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The branch to be merged uses reference-counted pointers, rather than storage keys, to refer to elements and regulators in tasks like these:
This simplifies code throughout the application by reducing the need to drag around context. A function that used to take an element storage key and a collection of elements as arguments can now just take a pointer to an element.
Implementation
Element and regulator collections
On the branch to be merged, an assembly's elements and regulators are stored in non-keyed collections. I chose B-tree sets, because I've read that they provide decent speed with low memory overhead as long as the collections don't get too large [1][2]. Since the branch to be merged already changes the type of the element and regulator collections, I took the opportunity to standardize on B-trees for other collections too, rather than using a mix of those and Fx hash collections like we do on the main branch.
Serial numbers
Rust pointers don't seem to be designed for use as identifiers, so the serial number system from the main branch still plays a useful role on the branch to be merged. The serial numbering code is moved into the
Serial
trait, where it can provide serial numbers for both elements and regulators.Rust version
The branch to be merged sets a Rust version in
Cargo.toml
, because it uses the trait object upcasting feature that was stabilized in the recently released Rust 1.86. Callrustup update
to update your toolchain.select
for click selection in outline 347981201cTests pass now that I've updated the continuous integration container image to Rust 1.86!
Indeed, works on my system, and tests pass on my system as well. Merging.