summaryrefslogtreecommitdiff
path: root/cli/file_fetcher.rs
diff options
context:
space:
mode:
authorKNnut <9387720+KNnut@users.noreply.github.com>2020-11-13 06:17:31 +0800
committerGitHub <noreply@github.com>2020-11-13 09:17:31 +1100
commit2c8439bc1e8118225c8ba4d64658c1c6b2182937 (patch)
treec3dde90a1bfbc2aba0bf993af8dc58d49444d1a4 /cli/file_fetcher.rs
parenta52d8839218e75311384fa8095d4cfde533ad923 (diff)
refactor(cli+core): various cleanups in Rust (#8336)
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r--cli/file_fetcher.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 933cbf203..50544bfd9 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -55,11 +55,7 @@ struct FileCache(Arc<Mutex<HashMap<ModuleSpecifier, File>>>);
impl FileCache {
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<File> {
let cache = self.0.lock().unwrap();
- if let Some(file) = cache.get(specifier) {
- Some(file.clone())
- } else {
- None
- }
+ cache.get(specifier).cloned()
}
pub fn insert(&self, specifier: ModuleSpecifier, file: File) -> Option<File> {
@@ -259,18 +255,16 @@ fn map_js_like_extension(
}
/// Remove shebangs from the start of source code strings
-fn strip_shebang(value: String) -> String {
+fn strip_shebang(mut value: String) -> String {
if value.starts_with("#!") {
- let value = if let Some(mid) = value.find('\n') {
+ if let Some(mid) = value.find('\n') {
let (_, rest) = value.split_at(mid);
- rest.to_string()
+ value = rest.to_string()
} else {
- "".to_string()
- };
- value
- } else {
- value
+ value.clear()
+ }
}
+ value
}
/// A structure for resolving, fetching and caching source files.