summaryrefslogtreecommitdiff
path: root/ext/node/ops/require.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-01 09:10:04 -0400
committerGitHub <noreply@github.com>2024-04-01 09:10:04 -0400
commit240b362c002d17bc2b676673ed1b9406683ff0c2 (patch)
treed0c3cdc099b7cac4f29ae17f7ba03ee01a01c877 /ext/node/ops/require.rs
parent8d158058e5abab14d122712a716979b865620995 (diff)
perf(node): put pkg json into an `Rc` (#23156)
Was doing a bit of debugging on why some stuff is not working in a personal project and ran a quick debug profile and saw it cloning the pkg json a lot. We should put this in an Rc.
Diffstat (limited to 'ext/node/ops/require.rs')
-rw-r--r--ext/node/ops/require.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs
index d6771c668..426c41995 100644
--- a/ext/node/ops/require.rs
+++ b/ext/node/ops/require.rs
@@ -542,10 +542,12 @@ where
)?;
let node_resolver = state.borrow::<Rc<NodeResolver>>();
let permissions = state.borrow::<P>();
- node_resolver.get_closest_package_json(
- &Url::from_file_path(filename).unwrap(),
- permissions,
- )
+ node_resolver
+ .get_closest_package_json(
+ &Url::from_file_path(filename).unwrap(),
+ permissions,
+ )
+ .map(|maybe_pkg| maybe_pkg.map(|pkg| (*pkg).clone()))
}
#[op2]
@@ -562,6 +564,7 @@ where
let package_json_path = PathBuf::from(package_json_path);
node_resolver
.load_package_json(permissions, package_json_path)
+ .map(|pkg| (*pkg).clone())
.ok()
}