From 3611ddadec057c9aa5e04afe9d2ede0b1f2f64f4 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 19 Aug 2023 21:47:13 +0400 Subject: [PATCH 1/2] Don't `.reserve()` without a need --- inquire/src/prompts/custom_type/mod.rs | 6 ------ inquire/src/prompts/dateselect/mod.rs | 6 ------ inquire/src/prompts/editor/mod.rs | 6 ------ inquire/src/prompts/password/mod.rs | 6 ------ inquire/src/prompts/text/mod.rs | 6 ------ 5 files changed, 30 deletions(-) diff --git a/inquire/src/prompts/custom_type/mod.rs b/inquire/src/prompts/custom_type/mod.rs index ff1a0302..319a05fe 100644 --- a/inquire/src/prompts/custom_type/mod.rs +++ b/inquire/src/prompts/custom_type/mod.rs @@ -196,12 +196,6 @@ where where V: CustomTypeValidator + 'static, { - // Directly make space for at least 5 elements, so we won't to re-allocate too often when - // calling this function repeatedly. - if self.validators.capacity() == 0 { - self.validators.reserve(5); - } - self.validators.push(Box::new(validator)); self } diff --git a/inquire/src/prompts/dateselect/mod.rs b/inquire/src/prompts/dateselect/mod.rs index 515b4457..6b890cd2 100644 --- a/inquire/src/prompts/dateselect/mod.rs +++ b/inquire/src/prompts/dateselect/mod.rs @@ -201,12 +201,6 @@ impl<'a> DateSelect<'a> { where V: DateValidator + 'static, { - // Directly make space for at least 5 elements, so we won't to re-allocate too often when - // calling this function repeatedly. - if self.validators.capacity() == 0 { - self.validators.reserve(5); - } - self.validators.push(Box::new(validator)); self } diff --git a/inquire/src/prompts/editor/mod.rs b/inquire/src/prompts/editor/mod.rs index b28d064b..a31e6976 100644 --- a/inquire/src/prompts/editor/mod.rs +++ b/inquire/src/prompts/editor/mod.rs @@ -163,12 +163,6 @@ impl<'a> Editor<'a> { where V: StringValidator + 'static, { - // Directly make space for at least 5 elements, so we won't to re-allocate too often when - // calling this function repeatedly. - if self.validators.capacity() == 0 { - self.validators.reserve(5); - } - self.validators.push(Box::new(validator)); self } diff --git a/inquire/src/prompts/password/mod.rs b/inquire/src/prompts/password/mod.rs index 3c25f0c9..e58646d6 100644 --- a/inquire/src/prompts/password/mod.rs +++ b/inquire/src/prompts/password/mod.rs @@ -218,12 +218,6 @@ impl<'a> Password<'a> { where V: StringValidator + 'static, { - // Directly make space for at least 5 elements, so we won't to re-allocate too often when - // calling this function repeatedly. - if self.validators.capacity() == 0 { - self.validators.reserve(5); - } - self.validators.push(Box::new(validator)); self } diff --git a/inquire/src/prompts/text/mod.rs b/inquire/src/prompts/text/mod.rs index 1f80e28b..398b4dc0 100644 --- a/inquire/src/prompts/text/mod.rs +++ b/inquire/src/prompts/text/mod.rs @@ -212,12 +212,6 @@ impl<'a> Text<'a> { where V: StringValidator + 'static, { - // Directly make space for at least 5 elements, so we won't to re-allocate too often when - // calling this function repeatedly. - if self.validators.capacity() == 0 { - self.validators.reserve(5); - } - self.validators.push(Box::new(validator)); self } From 0da4df227d66ff04ef2090947b2aba8fb72ad30d Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 19 Aug 2023 22:59:04 +0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a54d3a90..8c782be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ - MSRV is now explicitly set in the package definition. - Replaced `lazy_static` with `once_cell` as `once_cell::sync::Lazy` is being standardized and `lazy_static` is not actively maintained anymore. +### Internals + +- Removed some useless `Vec::reserve()` calls + ## [0.6.2] - 2023-05-07 - Allow usage of ANSI escape codes in prompts. [#136](https://github.com/mikaelmello/inquire/pull/136). Thanks to [@JimLynchCodes](https://github.com/JimLynchCodes) for reporting on [#135](https://github.com/mikaelmello/inquire/issues/135).