Skip to content

Commit 544cb42

Browse files
committed
Hoist path::Display on top of from_utf8_lossy()
1 parent b0b89a5 commit 544cb42

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

src/libstd/path/mod.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,10 @@ impl<'a, P: GenericPath> ToStr for Display<'a, P> {
547547
if self.filename {
548548
match self.path.filename() {
549549
None => ~"",
550-
Some(v) => from_utf8_with_replacement(v)
550+
Some(v) => str::from_utf8_lossy(v)
551551
}
552552
} else {
553-
from_utf8_with_replacement(self.path.as_vec())
553+
str::from_utf8_lossy(self.path.as_vec())
554554
}
555555
}
556556
}
@@ -635,29 +635,6 @@ fn contains_nul(v: &[u8]) -> bool {
635635
v.iter().any(|&x| x == 0)
636636
}
637637

638-
#[inline(always)]
639-
fn from_utf8_with_replacement(mut v: &[u8]) -> ~str {
640-
// FIXME (#9516): Don't decode utf-8 manually here once we have a good way to do it in str
641-
// This is a truly horrifically bad implementation, done as a functionality stopgap until
642-
// we have a proper utf-8 decoder. I don't really want to write one here.
643-
static REPLACEMENT_CHAR: char = '\uFFFD';
644-
645-
let mut s = str::with_capacity(v.len());
646-
while !v.is_empty() {
647-
let w = str::utf8_char_width(v[0]);
648-
if w == 0u {
649-
s.push_char(REPLACEMENT_CHAR);
650-
v = v.slice_from(1);
651-
} else if v.len() < w || !str::is_utf8(v.slice_to(w)) {
652-
s.push_char(REPLACEMENT_CHAR);
653-
v = v.slice_from(1);
654-
} else {
655-
s.push_str(unsafe { ::cast::transmute(v.slice_to(w)) });
656-
v = v.slice_from(w);
657-
}
658-
}
659-
s
660-
}
661638
#[cfg(test)]
662639
mod tests {
663640
use prelude::*;

0 commit comments

Comments
 (0)