From 182b0fe4c9e6a69540578d92c7f8cd3ae7911604 Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 3 Jul 2022 01:19:54 +0900 Subject: [PATCH] refactor with removing redundant flags --- src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1beeb6c..b6387bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 */ } @@ -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 '/' } @@ -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 */ } @@ -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 '/' }