Skip to content

Commit

Permalink
refactor with removing redundant flags
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jul 2, 2022
1 parent 39cb625 commit 182b0fe
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/lib.rs
Expand Up @@ -140,7 +140,6 @@ impl PathExt for Path {
use std::path::Component;

let mut buf = String::new();
let mut has_trailing_slash = false;
for c in self.components() {
match c {
Component::RootDir => { /* empty */ }
Expand All @@ -154,10 +153,9 @@ impl PathExt for Path {
Component::Normal(s) => buf.push_str(&s.to_string_lossy()),
}
buf.push('/');
has_trailing_slash = true;
}

if buf != "/" && has_trailing_slash {
if buf != "/" && buf.ends_with('/') {
buf.pop(); // Pop last '/'
}

Expand Down Expand Up @@ -191,7 +189,6 @@ impl PathExt for Path {
use std::path::Component;

let mut buf = String::new();
let mut has_trailing_slash = false;
for c in self.components() {
match c {
Component::RootDir => { /* empty */ }
Expand All @@ -205,10 +202,9 @@ impl PathExt for Path {
Component::Normal(s) => buf.push_str(s.to_str()?),
}
buf.push('/');
has_trailing_slash = true;
}

if buf != "/" && has_trailing_slash {
if buf != "/" && buf.ends_with('/') {
buf.pop(); // Pop last '/'
}

Expand Down

0 comments on commit 182b0fe

Please sign in to comment.