Summary: | Optimize checkWebRTCAvailability | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Alex Christensen <achristensen> | ||||
Component: | New Bugs | Assignee: | Alex Christensen <achristensen> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | darin, jonlee, mitz | ||||
Priority: | P2 | ||||||
Version: | WebKit Nightly Build | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
See Also: | https://bugs.webkit.org/show_bug.cgi?id=169147 | ||||||
Attachments: |
|
Description
Alex Christensen
2017-02-27 08:44:37 PST
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. 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. |