From 47273e15cf211a2e802dded0ce22513c5158ded9 Mon Sep 17 00:00:00 2001 From: Andrew Dirksen Date: Thu, 22 Nov 2018 12:17:35 -0800 Subject: [PATCH] use saturating_mul() instead of checked_mul().unwrap_or() --- src/common/stack.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/common/stack.rs b/src/common/stack.rs index 501da64..b4127d8 100644 --- a/src/common/stack.rs +++ b/src/common/stack.rs @@ -86,13 +86,7 @@ impl StackWithLimit { } // grows exponentially, just like Vec normally does // https://doc.rust-lang.org/1.26.0/src/alloc/raw_vec.rs.html#462 - let desired_len = self - .stack - .len() - .checked_mul(2) - .unwrap_or(usize::MAX) - .min(self.limit) - .max(1); + let desired_len = self.stack.len().saturating_mul(2).min(self.limit).max(1); let additional_len = desired_len - self.stack.len(); self.stack.reserve_exact(additional_len); } @@ -231,6 +225,8 @@ impl StackWithLimit { pub struct StackSize { num_elements: usize, // PhantomData is a zero-sized type for keeping track of T without rustc complaining. + // *const T or &'a T is recommended when T is not actually owned. + // https://doc.rust-lang.org/std/marker/struct.PhantomData.html#ownership-and-the-drop-check phantom: PhantomData<*const T>, }