diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-18 16:09:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-18 20:09:13 +0000 |
| commit | d33369c6c737718e02d61ae1b3a3231896d5a9b1 (patch) | |
| tree | 10c55cce5e347293cb644e086fdd57aa33e8427b /core | |
| parent | 4c1f3daa837932ec149b445468b95505f4775ef3 (diff) | |
perf(core): use static specifier in ExtensionFileSource (#18271)
Relanding #18264
-------
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'core')
| -rw-r--r-- | core/extensions.rs | 41 | ||||
| -rw-r--r-- | core/modules.rs | 30 | ||||
| -rw-r--r-- | core/runtime.rs | 4 |
3 files changed, 39 insertions, 36 deletions
diff --git a/core/extensions.rs b/core/extensions.rs index bba37ca3e..728ebd512 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -37,7 +37,7 @@ impl ExtensionFileSourceCode { #[derive(Clone, Debug)] pub struct ExtensionFileSource { - pub specifier: String, + pub specifier: &'static str, pub code: ExtensionFileSourceCode, } pub type OpFnRef = v8::FunctionCallback; @@ -189,11 +189,11 @@ macro_rules! extension { #[allow(unused_variables)] fn with_js(ext: &mut $crate::ExtensionBuilder) { $( ext.esm( - $crate::include_js_files!( $( dir $dir_esm , )? $( $esm , )* ) + $crate::include_js_files!( $name $( dir $dir_esm , )? $( $esm , )* ) ); )? $( ext.esm(vec![ExtensionFileSource { - specifier: "ext:setup".to_string(), + specifier: "ext:setup", code: ExtensionFileSourceCode::IncludedInBinary($esm_setup_script), }]); )? @@ -201,7 +201,7 @@ macro_rules! extension { ext.esm_entry_point($esm_entry_point); )? $( ext.js( - $crate::include_js_files!( $( dir $dir_js , )? $( $js , )* ) + $crate::include_js_files!( $name $( dir $dir_js , )? $( $js , )* ) ); )? } @@ -451,28 +451,11 @@ pub struct ExtensionBuilder { impl ExtensionBuilder { pub fn js(&mut self, js_files: Vec<ExtensionFileSource>) -> &mut Self { - let js_files = - // TODO(bartlomieju): if we're automatically remapping here, then we should - // use a different result struct that `ExtensionFileSource` as it's confusing - // when (and why) the remapping happens. - js_files.into_iter().map(|file_source| ExtensionFileSource { - specifier: format!("ext:{}/{}", self.name, file_source.specifier), - code: file_source.code, - }); self.js.extend(js_files); self } pub fn esm(&mut self, esm_files: Vec<ExtensionFileSource>) -> &mut Self { - let esm_files = esm_files - .into_iter() - // TODO(bartlomieju): if we're automatically remapping here, then we should - // use a different result struct that `ExtensionFileSource` as it's confusing - // when (and why) the remapping happens. - .map(|file_source| ExtensionFileSource { - specifier: format!("ext:{}/{}", self.name, file_source.specifier), - code: file_source.code, - }); self.esm.extend(esm_files); self } @@ -584,10 +567,10 @@ impl ExtensionBuilder { #[cfg(not(feature = "include_js_files_for_snapshotting"))] #[macro_export] macro_rules! include_js_files { - (dir $dir:literal, $($file:literal,)+) => { + ($name:ident dir $dir:literal, $($file:literal,)+) => { vec![ $($crate::ExtensionFileSource { - specifier: concat!($file).to_string(), + specifier: concat!("ext:", stringify!($name), "/", $file), code: $crate::ExtensionFileSourceCode::IncludedInBinary( include_str!(concat!($dir, "/", $file) )), @@ -595,10 +578,10 @@ macro_rules! include_js_files { ] }; - ($($file:literal,)+) => { + ($name:ident $($file:literal,)+) => { vec![ $($crate::ExtensionFileSource { - specifier: $file.to_string(), + specifier: concat!("ext:", stringify!($name), "/", $file), code: $crate::ExtensionFileSourceCode::IncludedInBinary( include_str!($file) ), @@ -610,10 +593,10 @@ macro_rules! include_js_files { #[cfg(feature = "include_js_files_for_snapshotting")] #[macro_export] macro_rules! include_js_files { - (dir $dir:literal, $($file:literal,)+) => { + ($name:ident dir $dir:literal, $($file:literal,)+) => { vec![ $($crate::ExtensionFileSource { - specifier: concat!($file).to_string(), + specifier: concat!("ext:", stringify!($name), "/", $file), code: $crate::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join($dir).join($file) ), @@ -621,10 +604,10 @@ macro_rules! include_js_files { ] }; - ($($file:literal,)+) => { + ($name:ident $($file:literal,)+) => { vec