mirror of
https://github.com/swc-project/swc.git
synced 2025-01-03 02:54:43 +03:00
perf(common): Avoid string re-allocation (#2318)
This commit is contained in:
parent
6a41e9a0be
commit
fee270fe57
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_common"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.13.1"
|
||||
version = "0.13.2"
|
||||
|
||||
[features]
|
||||
concurrent = ["parking_lot"]
|
||||
|
@ -23,6 +23,7 @@ use crate::{
|
||||
rustc_data_structures::stable_hasher::StableHasher,
|
||||
sync::{Lock, LockGuard, Lrc, MappedLockGuard},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
#[cfg(feature = "sourcemap")]
|
||||
use sourcemap::SourceMapBuilder;
|
||||
use std::{
|
||||
@ -30,12 +31,14 @@ use std::{
|
||||
cmp::{max, min},
|
||||
env, fs,
|
||||
hash::Hash,
|
||||
io::{self, Read},
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
static CURRENT_DIR: Lazy<Option<PathBuf>> = Lazy::new(|| env::current_dir().ok());
|
||||
|
||||
// _____________________________________________________________________________
|
||||
// SourceFile, MultiByteChar, FileName, FileLines
|
||||
//
|
||||
@ -64,14 +67,12 @@ impl FileLoader for RealFileLoader {
|
||||
if path.is_absolute() {
|
||||
Some(path.to_path_buf())
|
||||
} else {
|
||||
env::current_dir().ok().map(|cwd| cwd.join(path))
|
||||
CURRENT_DIR.as_ref().map(|cwd| cwd.join(path))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_file(&self, path: &Path) -> io::Result<String> {
|
||||
let mut src = String::new();
|
||||
fs::File::open(path)?.read_to_string(&mut src)?;
|
||||
Ok(src)
|
||||
fs::read_to_string(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user