From 990432d2539a809248d6cb384ac1732df40dae14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 15 Jul 2024 19:37:15 +0900 Subject: [PATCH 01/15] Dep --- crates/swc_ecma_codegen/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index efca69e793ce..8d2e840ebdbe 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -25,6 +25,7 @@ serde = { workspace = true } sourcemap = { workspace = true } tracing = { workspace = true } +swc_allocator = { version = "0.1.5", path = "../swc_allocator" } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common" } swc_ecma_ast = { version = "0.116.0", path = "../swc_ecma_ast" } From 6ac0f18c835878c3857818c4026359f782d81915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 15 Jul 2024 19:37:22 +0900 Subject: [PATCH 02/15] cargo lockfile --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index dcc366fbd301..a93aad4f31e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4151,6 +4151,7 @@ dependencies = [ "serde", "serde_json", "sourcemap", + "swc_allocator", "swc_atoms", "swc_common", "swc_ecma_ast", From d44278cf3f6d3f364bc7f143611a46594a368a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 15 Jul 2024 19:46:34 +0900 Subject: [PATCH 03/15] codegen --- crates/swc_ecma_codegen/benches/bench.rs | 5 +++-- crates/swc_ecma_codegen/benches/with_parse.rs | 3 ++- crates/swc_ecma_codegen/examples/sourcemap.rs | 3 ++- crates/swc_ecma_codegen/src/tests.rs | 5 +++-- crates/swc_ecma_codegen/src/text_writer/basic_impl.rs | 1 + crates/swc_ecma_codegen/tests/sourcemap.rs | 3 ++- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index 9c820aeeac3c..70567e6a81ad 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -1,6 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; +use swc_allocator::vec::Vec; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -84,7 +85,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); - let mut src_map_buf = vec![]; + let mut src_map_buf = Vec::new(); let module = parser .parse_module() .map_err(|e| e.into_diagnostic(handler).emit()) @@ -95,7 +96,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { - let mut buf = vec![]; + let mut buf = Vec::new(); { let mut emitter = Emitter { cfg: Default::default(), diff --git a/crates/swc_ecma_codegen/benches/with_parse.rs b/crates/swc_ecma_codegen/benches/with_parse.rs index d0ff27b97d61..a08132e44f6a 100644 --- a/crates/swc_ecma_codegen/benches/with_parse.rs +++ b/crates/swc_ecma_codegen/benches/with_parse.rs @@ -1,6 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; +use swc_allocator::vec::Vec; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -84,7 +85,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { b.iter(|| { let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); - let mut src_map_buf = vec![]; + let mut src_map_buf = Vec::new(); let module = parser .parse_module() .map_err(|e| e.into_diagnostic(handler).emit()) diff --git a/crates/swc_ecma_codegen/examples/sourcemap.rs b/crates/swc_ecma_codegen/examples/sourcemap.rs index e18522086244..c5f52074b3e9 100644 --- a/crates/swc_ecma_codegen/examples/sourcemap.rs +++ b/crates/swc_ecma_codegen/examples/sourcemap.rs @@ -9,6 +9,7 @@ use std::{ time::Instant, }; +use swc_allocator::vec::Vec; use swc_common::input::SourceFileInput; use swc_ecma_ast::*; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; @@ -30,7 +31,7 @@ fn parse_and_gen(entry: &Path) { .expect("failed to parse input as a module"); let mut code = vec![]; - let mut srcmap = vec![]; + let mut srcmap = Vec::new(); { let mut emitter = Emitter { diff --git a/crates/swc_ecma_codegen/src/tests.rs b/crates/swc_ecma_codegen/src/tests.rs index 3a89dd94d4fa..a86ba42ffa42 100644 --- a/crates/swc_ecma_codegen/src/tests.rs +++ b/crates/swc_ecma_codegen/src/tests.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +use swc_allocator::vec::Vec; use swc_common::{comments::SingleThreadedComments, FileName, SourceMap}; use swc_ecma_parser; use swc_ecma_testing::{exec_node_js, JsExecOptions}; @@ -44,11 +45,11 @@ impl Builder { where F: for<'aa> FnOnce(&mut Emitter<'aa, Box<(dyn WriteJs + 'aa)>, SourceMap>), { - let mut buf = vec![]; + let mut buf = Vec::new(); self.with(src, &mut buf, op); - String::from_utf8(buf).unwrap() + String::from_utf8_lossy(&buf).into_owned() } } diff --git a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs index e21389cc474f..055317a54feb 100644 --- a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs +++ b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs @@ -1,6 +1,7 @@ use std::io::Write; use rustc_hash::FxHashSet; +use swc_allocator::vec::Vec; use swc_common::{sync::Lrc, BytePos, LineCol, SourceMap, Span}; use super::{Result, WriteJs}; diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index 1fdaec759198..73ffa99d9767 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -3,6 +3,7 @@ use std::{fs::read_to_string, path::PathBuf}; use base64::prelude::{Engine, BASE64_STANDARD}; use rustc_hash::FxHashSet; use sourcemap::SourceMap; +use swc_allocator::vec::Vec; use swc_common::{comments::SingleThreadedComments, source_map::SourceMapGenConfig}; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{text_writer::WriteJs, Emitter}; @@ -315,7 +316,7 @@ fn identity(entry: PathBuf) { Some(&comments), ); let mut parser: Parser = Parser::new_from(lexer); - let mut src_map = vec![]; + let mut src_map = Vec::new(); { let mut wr = Box::new(swc_ecma_codegen::text_writer::JsWriter::new( From c58c81b58827c6249ffda1fe4c3f550520aadb93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 15 Jul 2024 20:02:35 +0900 Subject: [PATCH 04/15] Allocator::scope --- crates/swc_ecma_codegen/benches/bench.rs | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index 70567e6a81ad..a93be4478514 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -1,7 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_allocator::vec::Vec; +use swc_allocator::{vec::Vec, Allocator}; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -85,7 +85,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) { let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); - let mut src_map_buf = Vec::new(); let module = parser .parse_module() .map_err(|e| e.into_diagnostic(handler).emit()) @@ -96,25 +95,29 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { - let mut buf = Vec::new(); - { - let mut emitter = Emitter { - cfg: Default::default(), - comments: None, - cm: cm.clone(), - wr: swc_ecma_codegen::text_writer::JsWriter::new( - cm.clone(), - "\n", - &mut buf, - Some(&mut src_map_buf), - ), - }; + Allocator::default().scope(|| { + let mut src_map_buf = Vec::new(); - let _ = emitter.emit_module(&module); - } - black_box(buf); - let srcmap = cm.build_source_map(&src_map_buf); - black_box(srcmap); + let mut buf = Vec::new(); + { + let mut emitter = Emitter { + cfg: Default::default(), + comments: None, + cm: cm.clone(), + wr: swc_ecma_codegen::text_writer::JsWriter::new( + cm.clone(), + "\n", + &mut buf, + Some(&mut src_map_buf), + ), + }; + + let _ = emitter.emit_module(&module); + } + black_box(buf); + let srcmap = cm.build_source_map(&src_map_buf); + black_box(srcmap); + }) }); Ok(()) }); From 9d2b81d0cab22451ab377da745e4efb8f68841ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 21:49:55 +0900 Subject: [PATCH 05/15] typo --- crates/swc_ecma_ast/src/stmt.rs | 2 +- crates/swc_ecma_codegen/examples/sourcemap.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_ast/src/stmt.rs b/crates/swc_ecma_ast/src/stmt.rs index 32665b359a73..c19460bbcf7f 100644 --- a/crates/swc_ecma_ast/src/stmt.rs +++ b/crates/swc_ecma_ast/src/stmt.rs @@ -164,7 +164,7 @@ impl Stmt { } } -// Memory layout depedns on the version of rustc. +// Memory layout depends on the version of rustc. // #[cfg(target_pointer_width = "64")] // assert_eq_size!(Stmt, [u8; 56]); diff --git a/crates/swc_ecma_codegen/examples/sourcemap.rs b/crates/swc_ecma_codegen/examples/sourcemap.rs index c5f52074b3e9..1f004bb406cd 100644 --- a/crates/swc_ecma_codegen/examples/sourcemap.rs +++ b/crates/swc_ecma_codegen/examples/sourcemap.rs @@ -57,7 +57,7 @@ fn parse_and_gen(entry: &Path) { .expect("failed to process a module"); } -/// Usage: ./scripts/instruements path/to/input/file +/// Usage: ./scripts/instruments path/to/input/file fn main() { let main_file = env::args().nth(1).unwrap(); From fa80a47b7bb5b0ba1d44bb5523d3b29c1cb9a180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 21:54:53 +0900 Subject: [PATCH 06/15] Dep --- crates/swc_compiler_base/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_compiler_base/Cargo.toml b/crates/swc_compiler_base/Cargo.toml index 4a92bee18538..725e028915d8 100644 --- a/crates/swc_compiler_base/Cargo.toml +++ b/crates/swc_compiler_base/Cargo.toml @@ -21,6 +21,7 @@ rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sourcemap = { workspace = true } +swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common", features = [ From 3d6351f6dda8cea972b011d2a576b07d458e4640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 21:54:59 +0900 Subject: [PATCH 07/15] cargo lockifle --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index a93aad4f31e4..8f527f26c2ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3841,6 +3841,7 @@ dependencies = [ "serde", "serde_json", "sourcemap", + "swc_allocator", "swc_atoms", "swc_common", "swc_config", From bab7f8a9b33c44d42fcbe57c0c3fea1694817125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 21:56:43 +0900 Subject: [PATCH 08/15] more --- crates/swc_compiler_base/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/swc_compiler_base/src/lib.rs b/crates/swc_compiler_base/src/lib.rs index 2def122b13ba..51a644bae736 100644 --- a/crates/swc_compiler_base/src/lib.rs +++ b/crates/swc_compiler_base/src/lib.rs @@ -9,6 +9,7 @@ use once_cell::sync::Lazy; use rustc_hash::FxHashMap; #[allow(unused)] use serde::{Deserialize, Serialize}; +use swc_allocator::vec::Vec; use swc_atoms::JsWord; use swc_common::{ collections::AHashMap, @@ -171,10 +172,10 @@ where { let _timer = timer!("Compiler::print"); - let mut src_map_buf = vec![]; + let mut src_map_buf = Vec::new(); let src = { - let mut buf = vec![]; + let mut buf = Vec::new(); { let mut w = swc_ecma_codegen::text_writer::JsWriter::new( cm.clone(), From cb4f33ba9a79c55baea24e39953784e924f5963a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 22:28:21 +0900 Subject: [PATCH 09/15] Dep --- crates/swc_ecma_transforms_base/Cargo.toml | 1 + crates/swc_ecma_transforms_react/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/swc_ecma_transforms_base/Cargo.toml b/crates/swc_ecma_transforms_base/Cargo.toml index 0c397657ba75..44c430415c89 100644 --- a/crates/swc_ecma_transforms_base/Cargo.toml +++ b/crates/swc_ecma_transforms_base/Cargo.toml @@ -34,6 +34,7 @@ swc_ecma_ast = { version = "0.116.0", path = "../swc_ecma_ast" } swc_ecma_parser = { version = "0.147.0", path = "../swc_ecma_parser" } swc_ecma_utils = { version = "0.131.0", path = "../swc_ecma_utils" } swc_ecma_visit = { version = "0.102.0", path = "../swc_ecma_visit" } +swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } [dev-dependencies] codspeed-criterion-compat = { workspace = true } diff --git a/crates/swc_ecma_transforms_react/Cargo.toml b/crates/swc_ecma_transforms_react/Cargo.toml index 7c8ced316768..cfc3f6ee1851 100644 --- a/crates/swc_ecma_transforms_react/Cargo.toml +++ b/crates/swc_ecma_transforms_react/Cargo.toml @@ -27,6 +27,7 @@ serde = { workspace = true, features = ["derive"], optional = true } sha1 = { workspace = true } string_enum = { version = "0.4.4", path = "../string_enum" } +swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common" } swc_config = { version = "0.1.13", path = "../swc_config" } From 7740f763a414a92876727a234746b6b974f557cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 22:28:28 +0900 Subject: [PATCH 10/15] cargo lockfile --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8f527f26c2ea..3d70f05a4994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4594,6 +4594,7 @@ dependencies = [ "rustc-hash", "serde", "smallvec", + "swc_allocator", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -4765,6 +4766,7 @@ dependencies = [ "serde", "sha1", "string_enum", + "swc_allocator", "swc_atoms", "swc_common", "swc_config", From c2b85e8cffc5d6fe717f3df282a85d9fda002686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 22:30:04 +0900 Subject: [PATCH 11/15] dep --- crates/swc_fast_ts_strip/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_fast_ts_strip/Cargo.toml b/crates/swc_fast_ts_strip/Cargo.toml index 47d9eaa4d111..7d680bdfe285 100644 --- a/crates/swc_fast_ts_strip/Cargo.toml +++ b/crates/swc_fast_ts_strip/Cargo.toml @@ -13,6 +13,7 @@ version = "0.2.2" [dependencies] anyhow = { workspace = true } serde = { workspace = true, features = ["derive"] } +swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_common = { version = "0.35.0", path = "../swc_common", features = [ "sourcemap", From 05132329d253f49805641a75c2729222522ea5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 22:30:09 +0900 Subject: [PATCH 12/15] cargo lockfile --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 3d70f05a4994..ca80e56ce48e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4970,6 +4970,7 @@ dependencies = [ "codspeed-criterion-compat", "criterion", "serde", + "swc_allocator", "swc_common", "swc_ecma_ast", "swc_ecma_codegen", From 5060a9f6311450f9c495c384bcce93470b470331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Mon, 15 Jul 2024 22:30:56 +0900 Subject: [PATCH 13/15] More fix --- crates/swc_compiler_base/src/lib.rs | 3 +-- .../swc_ecma_transforms_react/src/pure_annotations/tests.rs | 5 +++-- crates/swc_fast_ts_strip/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/swc_compiler_base/src/lib.rs b/crates/swc_compiler_base/src/lib.rs index 51a644bae736..60592cae351a 100644 --- a/crates/swc_compiler_base/src/lib.rs +++ b/crates/swc_compiler_base/src/lib.rs @@ -9,7 +9,6 @@ use once_cell::sync::Lazy; use rustc_hash::FxHashMap; #[allow(unused)] use serde::{Deserialize, Serialize}; -use swc_allocator::vec::Vec; use swc_atoms::JsWord; use swc_common::{ collections::AHashMap, @@ -172,7 +171,7 @@ where { let _timer = timer!("Compiler::print"); - let mut src_map_buf = Vec::new(); + let mut src_map_buf = swc_allocator::vec::Vec::new(); let src = { let mut buf = Vec::new(); diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index b7aeb94bf43f..3901869cc764 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -1,3 +1,4 @@ +use swc_allocator::vec::Vec; use swc_common::{comments::SingleThreadedComments, sync::Lrc, FileName, Mark, SourceMap}; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_parser::{Parser, StringInput}; @@ -40,8 +41,8 @@ fn emit( comments: Lrc, program: &Module, ) -> String { - let mut src_map_buf = vec![]; - let mut buf = vec![]; + let mut src_map_buf = Vec::new(); + let mut buf = Vec::new(); { let writer = Box::new(JsWriter::new( source_map.clone(), diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index f2ea8400834b..4b3b9174010a 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -241,7 +241,7 @@ pub fn operate( let mut src = vec![]; let mut src_map_buf = if options.source_map { - Some(vec![]) + Some(Vec::new()) } else { None }; From 18648cf7ec2c274fbf110f99081478b75ec7322f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4/Donny?= Date: Tue, 16 Jul 2024 02:05:24 +0900 Subject: [PATCH 14/15] fix --- crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs | 2 +- crates/swc_fast_ts_strip/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index 3901869cc764..4ae2ae269867 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -42,7 +42,7 @@ fn emit( program: &Module, ) -> String { let mut src_map_buf = Vec::new(); - let mut buf = Vec::new(); + let mut buf = std::vec::Vec::new(); { let writer = Box::new(JsWriter::new( source_map.clone(), diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index 4b3b9174010a..92e2b78c9e90 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -241,7 +241,7 @@ pub fn operate( let mut src = vec![]; let mut src_map_buf = if options.source_map { - Some(Vec::new()) + Some(swc_allocator::vec::Vec::new()) } else { None }; From bc4c83b661b7a240baf7eea632b9684e653ff398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 16 Jul 2024 03:34:37 +0900 Subject: [PATCH 15/15] Use RAII --- crates/swc_ecma_codegen/benches/bench.rs | 42 ++++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index a93be4478514..af47725357e4 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -95,29 +95,29 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { - Allocator::default().scope(|| { - let mut src_map_buf = Vec::new(); + let alloc = Allocator::default(); + let _guard = unsafe { alloc.guard() }; + let mut src_map_buf = Vec::new(); - let mut buf = Vec::new(); - { - let mut emitter = Emitter { - cfg: Default::default(), - comments: None, - cm: cm.clone(), - wr: swc_ecma_codegen::text_writer::JsWriter::new( - cm.clone(), - "\n", - &mut buf, - Some(&mut src_map_buf), - ), - }; + let mut buf = Vec::new(); + { + let mut emitter = Emitter { + cfg: Default::default(), + comments: None, + cm: cm.clone(), + wr: swc_ecma_codegen::text_writer::JsWriter::new( + cm.clone(), + "\n", + &mut buf, + Some(&mut src_map_buf), + ), + }; - let _ = emitter.emit_module(&module); - } - black_box(buf); - let srcmap = cm.build_source_map(&src_map_buf); - black_box(srcmap); - }) + let _ = emitter.emit_module(&module); + } + black_box(buf); + let srcmap = cm.build_source_map(&src_map_buf); + black_box(srcmap); }); Ok(()) });