From 135902ac9338c20be09553aeb92eebcae8e5f0d7 Mon Sep 17 00:00:00 2001 From: h-a-n-a Date: Sun, 26 Dec 2021 17:24:26 +0800 Subject: [PATCH] refactor(core): optmize sourcemap type --- core/src/source_map.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/source_map.rs b/core/src/source_map.rs index 1aa453a..4549b01 100644 --- a/core/src/source_map.rs +++ b/core/src/source_map.rs @@ -24,20 +24,23 @@ pub struct SourceMap { impl SourceMap { pub fn new( mappings: &str, - file: Option, - names: Vec, - sources_content: Vec>, - source_root: Option, - sources: Vec>, + file: Option<&str>, + names: Vec<&str>, + sources_content: Vec>, + source_root: Option<&str>, + sources: Vec>, ) -> Self { Self { version: VERSION, mappings: String::from(mappings), - file, - names, - sources_content, - source_root, - sources, + file: file.map(|f| f.to_owned()), + names: names.iter().map(|&n| n.to_owned()).collect::>(), + sources_content: sources_content + .iter() + .map(|s| s.map(|s| s.to_owned())) + .collect(), + source_root: source_root.map(|s| s.to_owned()), + sources: sources.iter().map(|s| s.map(|s| s.to_owned())).collect(), } }