Optimize away an owned string in path_readlink.

This commit is contained in:
Dan Gohman
2019-09-29 11:52:09 -07:00
committed by Jakub Konka
parent 14bad3cb97
commit 4120d3b44f
2 changed files with 1 additions and 9 deletions

View File

@@ -508,14 +508,6 @@ pub(crate) fn path_from_slice<'a>(s: &'a [u8]) -> Result<&'a str> {
str::from_utf8(s).map_err(|_| Error::EILSEQ)
}
/// Creates owned WASI path from byte vector.
///
/// NB WASI spec requires bytes to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub(crate) fn path_from_vec<S: Into<Vec<u8>>>(s: S) -> Result<String> {
String::from_utf8(s.into()).map_err(|_| Error::EILSEQ)
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -652,7 +652,7 @@ pub(crate) unsafe fn path_readlink(
enc_usize_byref(memory, buf_used, 0)?;
let dirfd = dec_fd(dirfd);
let path = dec_slice_of::<u8>(memory, path_ptr, path_len).and_then(host::path_from_vec)?;
let path = dec_slice_of::<u8>(memory, path_ptr, path_len).and_then(host::path_from_slice)?;
trace!(" | (path_ptr,path_len)='{}'", &path);