mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 11:15:34 +00:00
8d585408dc
I also tried to avoid this change but, again, given the number of times I was repeating the same pattern of defining a static method just to forward a callback to an instance method, decided it was probably necessary. Without an easy way to do this, people are more likely to register observers rather than callbacks, for which we'll wind up paying a continued memory and performance penalty. This patch adds a helper which creates a type-safe preference callback function which forwards calls to an instance method on its closure object. The implementation is somewhat complicated, mainly due to the constraint that unregistering a callback requires passing the exact same function pointer that was used to register it. The patch achieves this by creating the callback function as a template, with the method pointer as a template parameter. As long as the Register and Unregister calls happen in the same translation unit, the same template instance is guaranteed to be used for both. The main difficulty is that, until C++ 17, there's no way match a value as a template parameter unless you know its complete type, or can at least compute its complete type based on earlier template parameters. That means that we need a macro to extract the type of the method, and construct the template with the full set of explicit parameters. MozReview-Commit-ID: 10N3R2SRtPc --HG-- extra : rebase_source : 7d0a8ddeb77e01d4a6f421459514e93bc0875598 |
||
---|---|---|
.. | ||
brotli | ||
fdlibm | ||
freetype2 | ||
libjar | ||
libmar | ||
libpref | ||
pdfium | ||
woff2 | ||
xz-embedded | ||
zlib | ||
moz.build |