| Summary: | [Cocoa] The function WebCore::systemHasBattery() should cache the result. | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Per Arne Vollan <pvollan> | ||||||
| Component: | WebKit Misc. | Assignee: | Per Arne Vollan <pvollan> | ||||||
| Status: | RESOLVED FIXED | ||||||||
| Severity: | Normal | CC: | bfulgham, darin, webkit-bug-importer | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | WebKit Nightly Build | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Attachments: |
|
||||||||
|
Description
Per Arne Vollan
2020-04-09 12:39:49 PDT
Created attachment 395991 [details]
Patch
Comment on attachment 395991 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=395991&action=review > Source/WebCore/platform/cocoa/SystemBattery.mm:45 > + static bool hasBattery = [] { Very confusing that we have two different global booleans of different types and scopes, but the same names. I suggest not defining a second boolean here, and just assigning a value to the first one. > Source/WebCore/platform/cocoa/SystemBattery.mm:61 > + return hasBattery; This would then be: return *hasBattery; Or you could write the function as: if (!hasBattery) { hasBattery = [] { <....> }(); } return *hasBattery; Created attachment 395992 [details]
Patch
(In reply to Darin Adler from comment #3) > Comment on attachment 395991 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=395991&action=review > > > Source/WebCore/platform/cocoa/SystemBattery.mm:45 > > + static bool hasBattery = [] { > > Very confusing that we have two different global booleans of different types > and scopes, but the same names. > > I suggest not defining a second boolean here, and just assigning a value to > the first one. > > > Source/WebCore/platform/cocoa/SystemBattery.mm:61 > > + return hasBattery; > > This would then be: > > return *hasBattery; > > Or you could write the function as: > > if (!hasBattery) { > hasBattery = [] { > <....> > }(); > } > return *hasBattery; Very good point, thanks for reviewing! Committed r259827: <https://trac.webkit.org/changeset/259827> All reviewed patches have been landed. Closing bug and clearing flags on attachment 395992 [details]. |