ddiakopoulos / libnyquist

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

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

Closed SamVanheer closed 2 years ago

SamVanheer commented 2 years ago

Fixes #65

SamVanheer commented 2 years 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 2 years ago

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

meshula commented 2 years ago

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

ddiakopoulos commented 2 years ago

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

SamVanheer commented 2 years ago

@ddiakopoulos Should be good now.