Bug 130495 - Refine BatteryStatus module
Summary: Refine BatteryStatus module
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jinwoo Song
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-19 20:27 PDT by Jinwoo Song
Modified: 2014-03-20 00:12 PDT (History)
3 users (show)

See Also:


Attachments
Patch (7.80 KB, patch)
2014-03-19 20:31 PDT, Jinwoo Song
no flags Details | Formatted Diff | Diff
Patch (7.83 KB, patch)
2014-03-19 23:33 PDT, Jinwoo Song
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jinwoo Song 2014-03-19 20:27:44 PDT
Small refinements:
 - Return PassRef instead of PassRefPtr in create method
 - Switched to nullptr instead of 0 where appropriate.
 - Removed unused function and header file.
 - Removed unnecessary empty lines.
Comment 1 Jinwoo Song 2014-03-19 20:31:05 PDT
Created attachment 227250 [details]
Patch
Comment 2 Andreas Kling 2014-03-19 23:07:53 PDT
Comment on attachment 227250 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=227250&action=review

> Source/WebCore/Modules/battery/BatteryManager.cpp:39
> -    RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(navigator)));
> +    Ref<BatteryManager> batteryManager(adoptRef(*new BatteryManager(navigator)));
>      batteryManager->suspendIfNeeded();
> -    return batteryManager.release();
> +    return batteryManager.get();

This will ref() and deref() the object twice, it would be more efficient to write it like this:

auto batteryManager = adoptRef(*new BatteryManager(navigator));
batteryManager.get().suspendIfNeeded();
return std::move(batteryManager);
Comment 3 Jinwoo Song 2014-03-19 23:30:56 PDT
(In reply to comment #2)
> (From update of attachment 227250 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=227250&action=review
> 
> > Source/WebCore/Modules/battery/BatteryManager.cpp:39
> > -    RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(navigator)));
> > +    Ref<BatteryManager> batteryManager(adoptRef(*new BatteryManager(navigator)));
> >      batteryManager->suspendIfNeeded();
> > -    return batteryManager.release();
> > +    return batteryManager.get();
> 
> This will ref() and deref() the object twice, it would be more efficient to write it like this:
> 
> auto batteryManager = adoptRef(*new BatteryManager(navigator));
> batteryManager.get().suspendIfNeeded();
> return std::move(batteryManager);

Thanks for advice! I'll modify it.
Comment 4 Jinwoo Song 2014-03-19 23:33:53 PDT
Created attachment 227260 [details]
Patch

Applied Kling's comment.
Comment 5 WebKit Commit Bot 2014-03-20 00:12:00 PDT
Comment on attachment 227260 [details]
Patch

Clearing flags on attachment: 227260

Committed r165950: <http://trac.webkit.org/changeset/165950>
Comment 6 WebKit Commit Bot 2014-03-20 00:12:10 PDT
All reviewed patches have been landed.  Closing bug.