Skip to content

Commit

Permalink
Delete ImageLoader::COUNT in favour of `ImageLoader::SUPPORTED_FORM…
Browse files Browse the repository at this point in the history
…ATS.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!
  • Loading branch information
andriyDev authored Oct 16, 2024
1 parent fbb5314 commit b109787
Showing 1 changed file with 2 additions and 68 deletions.
70 changes: 2 additions & 68 deletions crates/bevy_image/src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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;
}
Expand All @@ -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() {
Expand Down

0 comments on commit b109787

Please sign in to comment.