Skip to content

Commit eb86e4e

Browse files
committed
avoid a copy on non-windows
1 parent 2f50ede commit eb86e4e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/data_types.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// src/data_types.rs
22

3+
use std::borrow::Cow;
34
use std::hash::{Hash, Hasher, DefaultHasher};
45
use std::path::PathBuf;
56
use std::io::Write;
@@ -180,22 +181,24 @@ pub struct DataDirMnemonic<'a> {
180181
pub deriv_index: u32,
181182
}
182183

183-
fn normalize_challenge_id(challenge_id: &str) -> String {
184+
fn normalize_challenge_id(challenge_id: &str) -> Cow<str> {
184185
#[cfg(target_os = "windows")]
185186
{
186187
// Directories with '*' are not supported on windows
187-
challenge_id.replace("*", "")
188+
challenge_id.replace("*", "").into()
188189
}
189190
#[cfg(not(target_os = "windows"))]
190191
{
191-
challenge_id.to_string()
192+
challenge_id.into()
192193
}
193194
}
194195

195196
impl<'a> DataDir<'a> {
196197
pub fn challenge_dir(&'a self, base_dir: &str, challenge_id: &str) -> Result<PathBuf, String> {
198+
let challenge_id_normalized = normalize_challenge_id(challenge_id);
199+
197200
let mut path = PathBuf::from(base_dir);
198-
path.push(normalize_challenge_id(challenge_id));
201+
path.push(challenge_id_normalized.as_ref());
199202
Ok(path)
200203
}
201204

0 commit comments

Comments
 (0)