Optimize checkWebRTCAvailability
Created attachment 302843 [details] Patch
Comment on attachment 302843 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=302843&action=review > Source/WebKit2/UIProcess/WebPreferences.cpp:213 > + static bool available = false; > + static std::once_flag once; > + std::call_once(once, [&]() { > + void* libwebrtcLibrary = dlopen("libwebrtc.dylib", RTLD_LAZY); > + if (!libwebrtcLibrary) { > + available = false; > + return; > + } > + dlclose(libwebrtcLibrary); > + available = true; > + }); > + return available; Does this need to be called from arbitrary threads? If not, then I suggest just using global variable initialization rather than call_once. static bool available = [] { auto library = dlopen("libwebrtc.dylib", RTLD_LAZY); if (!library) return false; dlclose(library); return true; }(); return available; Fewer lines of code, also slightly more efficient.
http://trac.webkit.org/r213074
This check can be implemented by null-checking any of the symbols known to be exported from the dylib, which is a single branch. An implementation that involves a function call still seems unoptimal.
(In reply to comment #4) > This check can be implemented by null-checking any of the symbols known to > be exported from the dylib, which is a single branch. An implementation that > involves a function call still seems unoptimal. We should do that instead!
Filed follow-up bug 169147.