From c3c84ad027941b3011138d38d7797b202812fbb2 Mon Sep 17 00:00:00 2001 From: moonheart08 Date: Tue, 8 Sep 2020 10:35:35 -0500 Subject: [PATCH 1/2] Convert MAXIMUM_ZST_CAPACITY to be calculated in a const instead of multiple target_pointer_width checks. --- library/alloc/src/collections/vec_deque.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/collections/vec_deque.rs b/library/alloc/src/collections/vec_deque.rs index cc2ef25a5a7..664ba48fcf5 100644 --- a/library/alloc/src/collections/vec_deque.rs +++ b/library/alloc/src/collections/vec_deque.rs @@ -32,12 +32,8 @@ mod tests; const INITIAL_CAPACITY: usize = 7; // 2^3 - 1 const MINIMUM_CAPACITY: usize = 1; // 2 - 1 -#[cfg(target_pointer_width = "16")] -const MAXIMUM_ZST_CAPACITY: usize = 1 << (16 - 1); // Largest possible power of two -#[cfg(target_pointer_width = "32")] -const MAXIMUM_ZST_CAPACITY: usize = 1 << (32 - 1); // Largest possible power of two -#[cfg(target_pointer_width = "64")] -const MAXIMUM_ZST_CAPACITY: usize = 1 << (64 - 1); // Largest possible power of two + +const MAXIMUM_ZST_CAPACITY: usize = 1 << ((core::mem::size_of::() << 3) - 1); // Largest possible power of two /// A double-ended queue implemented with a growable ring buffer. /// From e02952c0cc6b360ac914f97da1dfcc46fd82f92c Mon Sep 17 00:00:00 2001 From: Braden Nelson Date: Tue, 8 Sep 2020 13:11:08 -0500 Subject: [PATCH 2/2] Update library/alloc/src/collections/vec_deque.rs Replace lshift with multiply Co-authored-by: Mara Bos --- library/alloc/src/collections/vec_deque.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque.rs b/library/alloc/src/collections/vec_deque.rs index 664ba48fcf5..f7f488f2f07 100644 --- a/library/alloc/src/collections/vec_deque.rs +++ b/library/alloc/src/collections/vec_deque.rs @@ -33,7 +33,7 @@ mod tests; const INITIAL_CAPACITY: usize = 7; // 2^3 - 1 const MINIMUM_CAPACITY: usize = 1; // 2 - 1 -const MAXIMUM_ZST_CAPACITY: usize = 1 << ((core::mem::size_of::() << 3) - 1); // Largest possible power of two +const MAXIMUM_ZST_CAPACITY: usize = 1 << (core::mem::size_of::() * 8 - 1); // Largest possible power of two /// A double-ended queue implemented with a growable ring buffer. ///