diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-08-27 20:50:05 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-27 20:50:05 +0530 |
| commit | 8e1c0e5141fa93f9169c28f32093bb7b30cd4e05 (patch) | |
| tree | 7525a6717f1fff55d3356d99657aa593148f0eb1 /runtime/fs_util.rs | |
| parent | 19fb9abe334313bec9f885818ed82ae754dd84e2 (diff) | |
perf(runtime): optimize allocations in read/write checks (#15631)
Diffstat (limited to 'runtime/fs_util.rs')
| -rw-r--r-- | runtime/fs_util.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs index 02bcddd76..30598e041 100644 --- a/runtime/fs_util.rs +++ b/runtime/fs_util.rs @@ -21,16 +21,15 @@ pub fn canonicalize_path(path: &Path) -> Result<PathBuf, Error> { Ok(canonicalized_path) } +#[inline] pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> { - let resolved_path = if path.is_absolute() { - path.to_owned() + if path.is_absolute() { + Ok(normalize_path(path)) } else { let cwd = current_dir().context("Failed to get current working directory")?; - cwd.join(path) - }; - - Ok(normalize_path(&resolved_path)) + Ok(normalize_path(&cwd.join(path))) + } } #[cfg(test)] |
