Skip to content

Commit

Permalink
perf: add more
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Mar 15, 2024
1 parent 6c81f88 commit 6c08c44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use crate::types::{RawToken, SourceMap, Token};
/// objects is generally not very comfortable. As a general aid this
/// type can help.
pub struct SourceMapBuilder {
file: Option<String>,
file: Option<Arc<str>>,
name_map: HashMap<Arc<str>, u32>,
names: Vec<Arc<str>>,
tokens: Vec<RawToken>,
source_map: HashMap<Arc<str>, u32>,
source_root: Option<String>,
source_root: Option<Arc<str>>,
sources: Vec<Arc<str>>,
source_contents: Vec<Option<Arc<str>>>,
sources_mapping: Vec<u32>,
Expand Down Expand Up @@ -53,7 +53,7 @@ impl SourceMapBuilder {
/// Creates a new source map builder and sets the file.
pub fn new(file: Option<&str>) -> SourceMapBuilder {
SourceMapBuilder {
file: file.map(str::to_owned),
file: file.map(Into::into),
name_map: HashMap::new(),
names: vec![],
tokens: vec![],
Expand All @@ -72,7 +72,7 @@ impl SourceMapBuilder {
}

/// Sets the file for the sourcemap (optional)
pub fn set_file<T: Into<String>>(&mut self, value: Option<T>) {
pub fn set_file<T: Into<Arc<str>>>(&mut self, value: Option<T>) {
self.file = value.map(Into::into);
}

Expand All @@ -82,7 +82,7 @@ impl SourceMapBuilder {
}

/// Sets a new value for the source_root.
pub fn set_source_root<T: Into<String>>(&mut self, value: Option<T>) {
pub fn set_source_root<T: Into<Arc<str>>>(&mut self, value: Option<T>) {
self.source_root = value.map(Into::into);
}

Expand Down
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub fn decode_regular(rsm: RawSourceMap) -> Result<SourceMap> {

// file sometimes is not a string for unexplicable reasons
let file = rsm.file.map(|val| match val {
Value::String(s) => s,
Value::String(s) => s.into(),
_ => "<invalid>".into(),
});

Expand Down
10 changes: 5 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ pub struct SourceMapIndex {
/// rejected with an error on reading.
#[derive(Clone, Debug)]
pub struct SourceMap {
pub(crate) file: Option<String>,
pub(crate) file: Option<Arc<str>>,
pub(crate) tokens: Vec<RawToken>,
pub(crate) index: Vec<(u32, u32, u32)>,
pub(crate) names: Vec<Arc<str>>,
pub(crate) source_root: Option<String>,
pub(crate) source_root: Option<Arc<str>>,
pub(crate) sources: Vec<Arc<str>>,
pub(crate) sources_prefixed: Option<Vec<Arc<str>>>,
pub(crate) sources_content: Vec<Option<SourceView>>,
Expand Down Expand Up @@ -574,7 +574,7 @@ impl SourceMap {
/// - `sources` a vector of source filenames
/// - `sources_content` optional source contents
pub fn new(
file: Option<String>,
file: Option<Arc<str>>,
tokens: Vec<RawToken>,
names: Vec<Arc<str>>,
sources: Vec<Arc<str>>,
Expand Down Expand Up @@ -619,7 +619,7 @@ impl SourceMap {
}

/// Sets a new value for the file.
pub fn set_file<T: Into<String>>(&mut self, value: Option<T>) {
pub fn set_file<T: Into<Arc<str>>>(&mut self, value: Option<T>) {
self.file = value.map(Into::into);
}

Expand All @@ -643,7 +643,7 @@ impl SourceMap {
}

/// Sets a new value for the source_root.
pub fn set_source_root<T: Into<String>>(&mut self, value: Option<T>) {
pub fn set_source_root<T: Into<Arc<str>>>(&mut self, value: Option<T>) {
self.source_root = value.map(Into::into);

match self.source_root.as_deref().filter(|rs| !rs.is_empty()) {
Expand Down

0 comments on commit 6c08c44

Please sign in to comment.