forked from rojo-rbx/rojo
Use WeakDom::into_raw for faster snapshot generation from models
This commit is contained in:
13
Cargo.lock
generated
13
Cargo.lock
generated
@@ -1633,11 +1633,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_binary"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68f424adb7a0a24ab4bd153be141035f1404ae40affed902fd2721b42cca7f86"
|
||||
dependencies = [
|
||||
"log",
|
||||
"lz4",
|
||||
"profiling",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection",
|
||||
"rbx_reflection_database",
|
||||
@@ -1647,8 +1646,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_dom_weak"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f7f524fb18f30d7065c82c4e87f747705679329810207e96169c6d4ec922d1f"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
@@ -1657,8 +1654,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_reflection"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8915748c8a3b2a92540e4e35e99ebd548df2d62b0a6cf38ae5d0081f0e611d5"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
@@ -1667,8 +1662,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_reflection_database"
|
||||
version = "0.2.4+roblox-504"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b41e8da85aa697cd04cef48e6dd7d96992786d2e322bafe1d3cc93045f4de1e1"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"rbx_reflection",
|
||||
@@ -1679,8 +1672,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_types"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d637383aa560cb675b7ea7a7778b945dab065ccc7c158f77b5455e27efadc6df"
|
||||
dependencies = [
|
||||
"base64 0.11.0",
|
||||
"bitflags",
|
||||
@@ -1694,8 +1685,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rbx_xml"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67387cd246cdec9251dd2451672541499ae6ce0a47c768b3ea9ee0a1becda9dd"
|
||||
dependencies = [
|
||||
"base64 0.11.0",
|
||||
"log",
|
||||
|
||||
20
Cargo.toml
20
Cargo.toml
@@ -44,17 +44,17 @@ harness = false
|
||||
memofs = { version = "0.2.0", path = "crates/memofs" }
|
||||
|
||||
# These dependencies can be uncommented when working on rbx-dom simultaneously
|
||||
# rbx_binary = { path = "../rbx-dom/rbx_binary" }
|
||||
# rbx_dom_weak = { path = "../rbx-dom/rbx_dom_weak" }
|
||||
# rbx_reflection = { path = "../rbx-dom/rbx_reflection" }
|
||||
# rbx_reflection_database = { path = "../rbx-dom/rbx_reflection_database" }
|
||||
# rbx_xml = { path = "../rbx-dom/rbx_xml" }
|
||||
rbx_binary = { path = "../rbx-dom/rbx_binary" }
|
||||
rbx_dom_weak = { path = "../rbx-dom/rbx_dom_weak" }
|
||||
rbx_reflection = { path = "../rbx-dom/rbx_reflection" }
|
||||
rbx_reflection_database = { path = "../rbx-dom/rbx_reflection_database" }
|
||||
rbx_xml = { path = "../rbx-dom/rbx_xml" }
|
||||
|
||||
rbx_binary = "0.6.4"
|
||||
rbx_dom_weak = "2.3.0"
|
||||
rbx_reflection = "4.2.0"
|
||||
rbx_reflection_database = "0.2.2"
|
||||
rbx_xml = "0.12.3"
|
||||
# rbx_binary = "0.6.4"
|
||||
# rbx_dom_weak = "2.3.0"
|
||||
# rbx_reflection = "4.2.0"
|
||||
# rbx_reflection_database = "0.2.2"
|
||||
# rbx_xml = "0.12.3"
|
||||
|
||||
anyhow = "1.0.44"
|
||||
backtrace = "0.3.61"
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use rbx_dom_weak::{
|
||||
types::{Ref, Variant},
|
||||
WeakDom,
|
||||
Instance, WeakDom,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -103,22 +103,28 @@ impl InstanceSnapshot {
|
||||
}
|
||||
|
||||
#[profiling::function]
|
||||
pub fn from_tree(tree: &WeakDom, id: Ref) -> Self {
|
||||
let instance = tree.get_by_ref(id).expect("instance did not exist in tree");
|
||||
pub fn from_tree(tree: WeakDom, id: Ref) -> Self {
|
||||
let (_, mut raw_tree) = tree.into_raw();
|
||||
Self::from_raw_tree(&mut raw_tree, id)
|
||||
}
|
||||
|
||||
fn from_raw_tree(raw_tree: &mut HashMap<Ref, Instance>, id: Ref) -> Self {
|
||||
let instance = raw_tree
|
||||
.remove(&id)
|
||||
.expect("instance did not exist in tree");
|
||||
|
||||
let children = instance
|
||||
.children()
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|id| Self::from_tree(tree, id))
|
||||
.map(|&id| Self::from_raw_tree(raw_tree, id))
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
snapshot_id: Some(id),
|
||||
metadata: InstanceMetadata::default(),
|
||||
name: Cow::Owned(instance.name.clone()),
|
||||
class_name: Cow::Owned(instance.class.clone()),
|
||||
properties: instance.properties.clone(),
|
||||
name: Cow::Owned(instance.name),
|
||||
class_name: Cow::Owned(instance.class),
|
||||
properties: instance.properties,
|
||||
children,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ pub fn snapshot_rbxm(
|
||||
let children = root_instance.children();
|
||||
|
||||
if children.len() == 1 {
|
||||
let snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0])
|
||||
let child = children[0];
|
||||
let snapshot = InstanceSnapshot::from_tree(temp_tree, child)
|
||||
.name(name)
|
||||
.metadata(
|
||||
InstanceMetadata::new()
|
||||
|
||||
@@ -24,7 +24,8 @@ pub fn snapshot_rbxmx(
|
||||
let children = root_instance.children();
|
||||
|
||||
if children.len() == 1 {
|
||||
let snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0])
|
||||
let child = children[0];
|
||||
let snapshot = InstanceSnapshot::from_tree(temp_tree, child)
|
||||
.name(name)
|
||||
.metadata(
|
||||
InstanceMetadata::new()
|
||||
|
||||
Reference in New Issue
Block a user