The function WebCore::systemHasBattery() should cache the result, since the return value of this function will be the same on a specific device.
rdar://problem/61331536
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].