Skip to content

Commit b109787

Browse files
authored
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!
1 parent fbb5314 commit b109787

File tree

1 file changed

+2
-68
lines changed

1 file changed

+2
-68
lines changed

crates/bevy_image/src/image_loader.rs

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,72 +12,6 @@ pub struct ImageLoader {
1212
}
1313

1414
impl ImageLoader {
15-
/// Number of image formats, used for computing other constants.
16-
const COUNT: usize = {
17-
let mut count = 0;
18-
#[cfg(feature = "avif")]
19-
{
20-
count += 1;
21-
}
22-
#[cfg(feature = "basis-universal")]
23-
{
24-
count += 1;
25-
}
26-
#[cfg(feature = "bmp")]
27-
{
28-
count += 1;
29-
}
30-
#[cfg(feature = "dds")]
31-
{
32-
count += 1;
33-
}
34-
#[cfg(feature = "ff")]
35-
{
36-
count += 1;
37-
}
38-
#[cfg(feature = "gif")]
39-
{
40-
count += 1;
41-
}
42-
#[cfg(feature = "ico")]
43-
{
44-
count += 1;
45-
}
46-
#[cfg(feature = "jpeg")]
47-
{
48-
count += 1;
49-
}
50-
#[cfg(feature = "ktx2")]
51-
{
52-
count += 1;
53-
}
54-
#[cfg(feature = "pnm")]
55-
{
56-
count += 1;
57-
}
58-
#[cfg(feature = "png")]
59-
{
60-
count += 1;
61-
}
62-
#[cfg(feature = "qoi")]
63-
{
64-
count += 1;
65-
}
66-
#[cfg(feature = "tga")]
67-
{
68-
count += 1;
69-
}
70-
#[cfg(feature = "tiff")]
71-
{
72-
count += 1;
73-
}
74-
#[cfg(feature = "webp")]
75-
{
76-
count += 1;
77-
}
78-
count
79-
};
80-
8115
/// Full list of supported formats.
8216
pub const SUPPORTED_FORMATS: &'static [ImageFormat] = &[
8317
#[cfg(feature = "avif")]
@@ -116,7 +50,7 @@ impl ImageLoader {
11650
const COUNT_FILE_EXTENSIONS: usize = {
11751
let mut count = 0;
11852
let mut idx = 0;
119-
while idx < Self::COUNT {
53+
while idx < Self::SUPPORTED_FORMATS.len() {
12054
count += Self::SUPPORTED_FORMATS[idx].to_file_extensions().len();
12155
idx += 1;
12256
}
@@ -128,7 +62,7 @@ impl ImageLoader {
12862
let mut exts = [""; Self::COUNT_FILE_EXTENSIONS];
12963
let mut ext_idx = 0;
13064
let mut fmt_idx = 0;
131-
while fmt_idx < Self::COUNT {
65+
while fmt_idx < Self::SUPPORTED_FORMATS.len() {
13266
let mut off = 0;
13367
let fmt_exts = Self::SUPPORTED_FORMATS[fmt_idx].to_file_extensions();
13468
while off < fmt_exts.len() {

0 commit comments

Comments
 (0)