ddiakopoulos / libnyquist

:microphone: Cross platform C++11 library for decoding audio (mp3, wav, ogg, opus, flac, etc)
BSD 2-Clause "Simplified" License
534 stars 64 forks source link

Make magic_map a global constant to avoid creating temporary instances on every call #66

Closed SamVanheer closed 1 year ago

SamVanheer commented 1 year ago

Fixes #65

SamVanheer commented 1 year ago

The assumption here was that making magic_map const would cause it to be statically created and referenced, rather than created on every call to Load(). Is that not the case? Would it then be simplest to just add static to magic_map to accomplish it?

That's the simplest way, but that will add a compiler-generated check to see if it has been initialized every time the function is called. This function can be called thousands of times in a short time period so that extra overhead can add up.

SamVanheer commented 1 year ago

Are there any changes that need to be made or is this fine?

meshula commented 1 year ago

The change looks good to me. Thanks for the answer to my question, I see why you structured it that way.

ddiakopoulos commented 1 year ago

@SamVanheer Could you resolve the conflict -- then I'll be happy to merge!

SamVanheer commented 1 year ago

@ddiakopoulos Should be good now.