mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
perf: reduce IO
This commit is contained in:
parent
a7dbdb7c8d
commit
9e782bef2e
5 changed files with 51 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
|||
//! provides utilities for parser, compiler, and vm crate.
|
||||
use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
pub mod cache;
|
||||
pub mod config;
|
||||
|
@ -192,6 +192,33 @@ pub fn normalize_path(path: PathBuf) -> PathBuf {
|
|||
PathBuf::from(lower)
|
||||
}
|
||||
|
||||
pub fn cheap_canonicalize_path(path: &Path) -> PathBuf {
|
||||
let mut components = path.components().peekable();
|
||||
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
|
||||
components.next();
|
||||
PathBuf::from(c.as_os_str())
|
||||
} else {
|
||||
PathBuf::new()
|
||||
};
|
||||
|
||||
for component in components {
|
||||
match component {
|
||||
Component::Prefix(..) => unreachable!(),
|
||||
Component::RootDir => {
|
||||
ret.push(component.as_os_str());
|
||||
}
|
||||
Component::CurDir => {}
|
||||
Component::ParentDir => {
|
||||
ret.pop();
|
||||
}
|
||||
Component::Normal(c) => {
|
||||
ret.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use erg_common::trim_eliminate_top_indent;
|
||||
/// let code = r#"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue