Skip to content

Commit

Permalink
Reserve space for additional instances in binary deserializer (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler authored Oct 30, 2024
1 parent 9cbfcd5 commit 70e70fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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/465
[#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

0 comments on commit 70e70fd

Please sign in to comment.