Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserve space for additional instances in binary deserializer #465

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rbx_binary/src/deserializer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ impl<'db, R: Read> DeserializerState<'db, R> {
deserializer: &'db Deserializer<'db>,
mut input: R,
) -> Result<Self, InnerError> {
let tree = WeakDom::new(InstanceBuilder::new("DataModel"));
let mut tree = WeakDom::new(InstanceBuilder::new("DataModel"));

let header = FileHeader::decode(&mut input)?;

let type_infos = HashMap::with_capacity(header.num_types as usize);
let instances_by_ref = HashMap::with_capacity(1 + header.num_instances as usize);

tree.reserve(header.num_instances as usize);

Ok(DeserializerState {
deserializer,
input,
Expand Down
2 changes: 2 additions & 0 deletions rbx_dom_weak/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ where
* Added `UstrMapExt`, a helper trait providing convenience methods `UstrMap::new` and `UstrMap::with_capacity`.
* Added re-exports for `ustr` (a convenience function for creating `Ustr`s), `Ustr`, `UstrMap`, and `UstrSet`.
* Added `InstanceBuilder::with_property_capacity`, which can preallocate an `InstanceBuilder`'s property table. [#464]
* Added `WeakDom::reserve`, which can preallocate additional space for instances in the `WeakDom`. [#465]

[#465]: https://github.com/rojo-rbx/rbx-dom/pull/464
kennethloeffler marked this conversation as resolved.
Show resolved Hide resolved
[#464]: https://github.com/rojo-rbx/rbx-dom/pull/464

## 2.9.0 (2024-08-22)
Expand Down
6 changes: 6 additions & 0 deletions rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ impl WeakDom {
dom
}

/// Reserve at least enough space for `additional` number of instances in
/// the WeakDom.
pub fn reserve(&mut self, additional: usize) {
self.instances.reserve(additional);
}

/// Consumes the WeakDom, returning its underlying root ref and backing
/// storage. This method is useful when tree-preserving operations are too
/// slow.
Expand Down