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

Wrapping the String type with Arc to reduce the cost of one clone. #308

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
11 changes: 7 additions & 4 deletions src/inner_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
task::Poll,
time::Duration,
};
use std::sync::Arc;
use tokio_util::sync::CancellationToken;

/// Wrapper trait to make the `InnerRuntime` generic over the runtime types
Expand Down Expand Up @@ -745,7 +746,8 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
.translate_cjs(&module_specifier, &code)
.await?;

let fast_code = deno_core::FastString::from(code.clone());
let arc_code = Arc::new(code);
let fast_code = deno_core::FastString::from(arc_code.clone());

let s_modid = self
.deno_runtime()
Expand All @@ -755,7 +757,7 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
// Update source map cache
self.module_loader.insert_source_map(
module_specifier.as_str(),
code,
arc_code.clone().to_string(),
sourcemap.map(|s| s.to_vec()),
);

Expand All @@ -777,7 +779,8 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
.translate_cjs(&module_specifier, &code)
.await?;

let fast_code = deno_core::FastString::from(code.clone());
let arc_code = Arc::new(code);
let fast_code = deno_core::FastString::from(arc_code.clone());

let module_id = self
.deno_runtime()
Expand All @@ -787,7 +790,7 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
// Update source map cache
self.module_loader.insert_source_map(
module_specifier.as_str(),
code,
arc_code.to_string(),
sourcemap.map(|s| s.to_vec()),
);

Expand Down