Patchwork [2,of,2] rust-discovery: use while loop instead of match + break

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 16, 2019, 11:28 a.m.
Message ID <7c07a39ae2557c7a41a5.1565954892@mimosa>
Download mbox | patch
Permalink /patch/41315/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 16, 2019, 11:28 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1565948045 -32400
#      Fri Aug 16 18:34:05 2019 +0900
# Node ID 7c07a39ae2557c7a41a56ff2552ae635b8c5d880
# Parent  efcd5928d84224dea38b08d1dc1e135b91e0c045
rust-discovery: use while loop instead of match + break

This looks slightly nicer.
Augie Fackler - Aug. 16, 2019, 9:03 p.m.
queued, thanks

> On Aug 16, 2019, at 07:28, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1565948045 -32400
> #      Fri Aug 16 18:34:05 2019 +0900
> # Node ID 7c07a39ae2557c7a41a56ff2552ae635b8c5d880
> # Parent  efcd5928d84224dea38b08d1dc1e135b91e0c045
> rust-discovery: use while loop instead of match + break
> 
> This looks slightly nicer.
> 
> diff --git a/rust/hg-core/src/discovery.rs b/rust/hg-core/src/discovery.rs
> --- a/rust/hg-core/src/discovery.rs
> +++ b/rust/hg-core/src/discovery.rs
> @@ -65,13 +65,7 @@ where
>     let mut visit: VecDeque<Revision> = heads.into_iter().collect();
>     let mut factor: u32 = 1;
>     let mut seen: HashSet<Revision> = HashSet::new();
> -    loop {
> -        let current = match visit.pop_front() {
> -            None => {
> -                break;
> -            }
> -            Some(r) => r,
> -        };
> +    while let Some(current) = visit.pop_front() {
>         if !seen.insert(current) {
>             continue;
>         }
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/rust/hg-core/src/discovery.rs b/rust/hg-core/src/discovery.rs
--- a/rust/hg-core/src/discovery.rs
+++ b/rust/hg-core/src/discovery.rs
@@ -65,13 +65,7 @@  where
     let mut visit: VecDeque<Revision> = heads.into_iter().collect();
     let mut factor: u32 = 1;
     let mut seen: HashSet<Revision> = HashSet::new();
-    loop {
-        let current = match visit.pop_front() {
-            None => {
-                break;
-            }
-            Some(r) => r,
-        };
+    while let Some(current) = visit.pop_front() {
         if !seen.insert(current) {
             continue;
         }