Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movie: simplify silly loop #12689

Merged
merged 1 commit into from Apr 6, 2024
Merged

Movie: simplify silly loop #12689

merged 1 commit into from Apr 6, 2024

Conversation

Tilka
Copy link
Member

@Tilka Tilka commented Apr 6, 2024

NFC

@Pokechu22 Pokechu22 self-requested a review April 6, 2024 16:34
@mitaclaw
Copy link
Contributor

mitaclaw commented Apr 6, 2024

A more literal interpretation of this loop would be std::count_if, though std::all_of could also be a good rework. Initializing an array to compare against seems inefficient.

Copy link
Contributor

@Pokechu22 Pokechu22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a previous version of this loop was added in ca650d4, where it looked like this:

for (int i=0; i<16; i++)
{
if (tmpHeader.md5[i] != 0)
continue;
if (i == 15)
return;
}
Core::DisplayMessage("Checking md5 of game file against recorded game...", 2000);

but that returns if the last byte in the md5 is 0, rather than all bytes. (If it used break instead of continue I think it would work?)

That was changed to the current loop with two variables in 1917f83:

for (int i=0, n=0; i<16; i++)
{
if (tmpHeader.md5[i] != 0)
continue;
n++;
if (n == 16)
return;
}
Core::DisplayMessage("Verifying checksum...", 2000);

It's worth noting that std::array was only used here in 75d056b; before it was a C-style array.

A comment like this might be helpful:

  // Very old DTM files don't include an md5, in which case that previously-reserved area is all zeros.
  // Skip the MD5 check in that case.

@JosJuice
Copy link
Member

JosJuice commented Apr 6, 2024

A more literal interpretation of this loop would be std::count_if, though std::all_of could also be a good rework. Initializing an array to compare against seems inefficient.

It depends on how the compiler optimizes it. If we're lucky, the compiler might be able to skip putting the std::array on the stack, putting it in two registers instead. We'd need to see the emitted assembly to know for sure. Personally, since this runs super rarely, I don't care too much either way.

@Tilka
Copy link
Member Author

Tilka commented Apr 6, 2024

Added a comment.

@AdmiralCurtiss AdmiralCurtiss merged commit 116da3a into dolphin-emu:master Apr 6, 2024
11 checks passed
@Tilka Tilka deleted the movie branch April 6, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants