From b1097877646dca3506a689e7bde90e6a0afd5251 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Tue, 15 Oct 2024 17:50:50 -0700 Subject: [PATCH] Delete `ImageLoader::COUNT` in favour of `ImageLoader::SUPPORTED_FORMATS.len()`. (#15939) # Objective - This is a followup to #15812. ## Solution I just deleted the `COUNT` const and replaced it. I didn't realize for loops are not const yet, so improving the other const variables is not obvious. Note: `slice::len` has been const since Rust 1.39, so we're not relying on a brand new feature or anything. ## Testing - It builds! --- crates/bevy_image/src/image_loader.rs | 70 +-------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/crates/bevy_image/src/image_loader.rs b/crates/bevy_image/src/image_loader.rs index 397b0ba727..0ad3e41006 100644 --- a/crates/bevy_image/src/image_loader.rs +++ b/crates/bevy_image/src/image_loader.rs @@ -12,72 +12,6 @@ pub struct ImageLoader { } impl ImageLoader { - /// Number of image formats, used for computing other constants. - const COUNT: usize = { - let mut count = 0; - #[cfg(feature = "avif")] - { - count += 1; - } - #[cfg(feature = "basis-universal")] - { - count += 1; - } - #[cfg(feature = "bmp")] - { - count += 1; - } - #[cfg(feature = "dds")] - { - count += 1; - } - #[cfg(feature = "ff")] - { - count += 1; - } - #[cfg(feature = "gif")] - { - count += 1; - } - #[cfg(feature = "ico")] - { - count += 1; - } - #[cfg(feature = "jpeg")] - { - count += 1; - } - #[cfg(feature = "ktx2")] - { - count += 1; - } - #[cfg(feature = "pnm")] - { - count += 1; - } - #[cfg(feature = "png")] - { - count += 1; - } - #[cfg(feature = "qoi")] - { - count += 1; - } - #[cfg(feature = "tga")] - { - count += 1; - } - #[cfg(feature = "tiff")] - { - count += 1; - } - #[cfg(feature = "webp")] - { - count += 1; - } - count - }; - /// Full list of supported formats. pub const SUPPORTED_FORMATS: &'static [ImageFormat] = &[ #[cfg(feature = "avif")] @@ -116,7 +50,7 @@ impl ImageLoader { const COUNT_FILE_EXTENSIONS: usize = { let mut count = 0; let mut idx = 0; - while idx < Self::COUNT { + while idx < Self::SUPPORTED_FORMATS.len() { count += Self::SUPPORTED_FORMATS[idx].to_file_extensions().len(); idx += 1; } @@ -128,7 +62,7 @@ impl ImageLoader { let mut exts = [""; Self::COUNT_FILE_EXTENSIONS]; let mut ext_idx = 0; let mut fmt_idx = 0; - while fmt_idx < Self::COUNT { + while fmt_idx < Self::SUPPORTED_FORMATS.len() { let mut off = 0; let fmt_exts = Self::SUPPORTED_FORMATS[fmt_idx].to_file_extensions(); while off < fmt_exts.len() {