[pdq] Constant initialize DCT buffer #1518
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Changed DCT buffer to be constant initialized.
The function which initializes and returns the DCT static buffer was updated to be reentrant in #1338 in pdqhashing.cpp. The change was to protect filling the static buffer from multiple threads by using std::call_once. However, this is unnecessary because it can just be constant initialized because the buffer is never modified after initialization.
In this PR, the buffer is changed to a
std::array
, so it can be returned from the function. The convenience pointers to its offsets are changed to references infillFloatLumaFromRGB
.All of the changes are supported by C++11, which is the default for pdq.
Other misc changes:
Updated some variable names in the function for readability.
Added
venv/
to.gitignore
for dev convenienceReferences:
cppreference.com initialization article (I don't own the standard):
Anecdote: If compiled with C++20 (ex. https://godbolt.org/z/jejqn6M4Y), this function actually turns into a lookup table. I thought that was interesting.
Test Plan
Tested vpdq and pdq. All tests pass. No concurrency issues when ran with sanitizers (vpdq CI does this).