I'm looking at cap_std::fs_utf8
and seeing that it's calling from_utf8
on the supplied paths quite frequently, which is Ok(path.as_ref().as_std_path().to_path_buf())
, This is dispite it only really needing a Path
, not a PathBuf
. Is there any particular reason for this or is fs_utf8 just not widely used?
It looks like maybe a real conversion might be required for arf_strings, but even they shouldn't have any additional data for valid UTF-8
Good find! There isn't a particular reason for it; the original code used arf_strings, and we didn't notice this when arf_strings were made optional.
oddly this issue was introduced after that
oh, no, that's not true; it was introduced in the same commit
actually, looking at the subsequent code I don't really see why they would need this allocation _either_, since afaict an arf_string of valid utf-8 that said valid utf-8
An arf_string of an ill-formed string needs an allocation.
I believe from_utf8
has returned a PathBuf
since it was first introduced.
I've now submitted https://github.com/bytecodealliance/cap-std/pull/285 which fixes this, for the non-arf-strings case.
Last updated: Dec 23 2024 at 12:05 UTC