Skip to content

Commit

Permalink
Remove use of unstable box syntax.
Browse files Browse the repository at this point in the history
http://www.robohornet.org gives a score of 101.36 on master,
and 102.68 with this PR. The latter is slightly better,
but probably within noise level.
So it looks like this PR does not affect DOM performance.

This is expected since `Box::new` is defined as:

```rust
impl<T> Box<T> {
    #[inline(always)]
    pub fn new(x: T) -> Box<T> {
        box x
    }
}
```

With inlining, it should compile to the same as box syntax.
  • Loading branch information
SimonSapin committed Oct 16, 2017
1 parent a5100e3 commit aa15dc2
Show file tree
Hide file tree
Showing 270 changed files with 580 additions and 514 deletions.
8 changes: 4 additions & 4 deletions components/script/dom/abstractworkerglobalscope.rs
Expand Up @@ -24,10 +24,10 @@ impl<T: JSTraceable + DomObject + 'static> ScriptChan for SendableWorkerScriptCh
}

fn clone(&self) -> Box<ScriptChan + Send> {
box SendableWorkerScriptChan {
Box::new(SendableWorkerScriptChan {
sender: self.sender.clone(),
worker: self.worker.clone(),
}
})
}
}

Expand All @@ -48,10 +48,10 @@ impl<T: JSTraceable + DomObject + 'static> ScriptChan for WorkerThreadWorkerChan
}

fn clone(&self) -> Box<ScriptChan + Send> {
box WorkerThreadWorkerChan {
Box::new(WorkerThreadWorkerChan {
sender: self.sender.clone(),
worker: self.worker.clone(),
}
})
}
}

Expand Down
20 changes: 12 additions & 8 deletions components/script/dom/attr.rs
Expand Up @@ -64,14 +64,18 @@ impl Attr {
prefix: Option<Prefix>,
owner: Option<&Element>)
-> DomRoot<Attr> {
reflect_dom_object(box Attr::new_inherited(local_name,
value,
name,
namespace,
prefix,
owner),
window,
AttrBinding::Wrap)
reflect_dom_object(
Box::new(Attr::new_inherited(
local_name,
value,
name,
namespace,
prefix,
owner
)),
window,
AttrBinding::Wrap
)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/beforeunloadevent.rs
Expand Up @@ -33,7 +33,7 @@ impl BeforeUnloadEvent {
}

pub fn new_uninitialized(window: &Window) -> DomRoot<BeforeUnloadEvent> {
reflect_dom_object(box BeforeUnloadEvent::new_inherited(),
reflect_dom_object(Box::new(BeforeUnloadEvent::new_inherited()),
window,
BeforeUnloadEventBinding::Wrap)
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/interface.rs
Expand Up @@ -226,7 +226,7 @@ pub unsafe fn create_global_object(
// avoid getting trace hooks called on a partially initialized object.
JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, PrivateValue(private));
let proto_array: Box<ProtoOrIfaceArray> =
box [0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH];
Box::new([0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH]);
JS_SetReservedSlot(rval.get(),
DOM_PROTOTYPE_SLOT,
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bindings/iterable.rs
Expand Up @@ -62,12 +62,12 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
type_: IteratorType,
wrap: unsafe fn(*mut JSContext, &GlobalScope, Box<IterableIterator<T>>)
-> DomRoot<Self>) -> DomRoot<Self> {
let iterator = box IterableIterator {
let iterator = Box::new(IterableIterator {
reflector: Reflector::new(),
type_: type_,
iterable: Dom::from_ref(iterable),
index: Cell::new(0),
};
});
reflect_dom_object(iterator, &*iterable.global(), wrap)
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/trace.rs
Expand Up @@ -759,7 +759,7 @@ unsafe impl<T: JSTraceable + 'static> JSTraceable for RootedTraceableBox<T> {
impl<T: JSTraceable + 'static> RootedTraceableBox<T> {
/// DomRoot a JSTraceable thing for the life of this RootedTraceable
pub fn new(traceable: T) -> RootedTraceableBox<T> {
let traceable = Box::into_raw(box traceable);
let traceable = Box::into_raw(Box::new(traceable));
unsafe {
RootedTraceableSet::add(traceable);
}
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bindings/weakref.rs
Expand Up @@ -56,10 +56,10 @@ pub trait WeakReferenceable: DomObject + Sized {
.to_private() as *mut WeakBox<Self>;
if ptr.is_null() {
trace!("Creating new WeakBox holder for {:p}.", self);
ptr = Box::into_raw(box WeakBox {
ptr = Box::into_raw(Box::new(WeakBox {
count: Cell::new(1),
value: Cell::new(Some(NonZero::new_unchecked(self))),
});
}));
JS_SetReservedSlot(object, DOM_WEAK_SLOT, PrivateValue(ptr as *const c_void));
}
let box_ = &*ptr;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/blob.rs
Expand Up @@ -80,7 +80,7 @@ impl Blob {
pub fn new(
global: &GlobalScope, blob_impl: BlobImpl, typeString: String)
-> DomRoot<Blob> {
let boxed_blob = box Blob::new_inherited(blob_impl, typeString);
let boxed_blob = Box::new(Blob::new_inherited(blob_impl, typeString));
reflect_dom_object(boxed_blob, global, BlobBinding::Wrap)
}

Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/bluetooth.rs
Expand Up @@ -132,7 +132,7 @@ impl Bluetooth {
}

pub fn new(global: &GlobalScope) -> DomRoot<Bluetooth> {
reflect_dom_object(box Bluetooth::new_inherited(),
reflect_dom_object(Box::new(Bluetooth::new_inherited()),
global,
BluetoothBinding::Wrap)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ pub fn response_async<T: AsyncBluetoothListener + DomObject + 'static>(
promise: Some(TrustedPromise::new(promise.clone())),
receiver: Trusted::new(receiver),
}));
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
ROUTER.add_route(action_receiver.to_opaque(), Box::new(move |message| {
struct ListenerTask<T: AsyncBluetoothListener + DomObject> {
context: Arc<Mutex<BluetoothContext<T>>>,
action: BluetoothResponseResult,
Expand All @@ -249,7 +249,7 @@ pub fn response_async<T: AsyncBluetoothListener + DomObject + 'static>(
if let Err(err) = result {
warn!("failed to deliver network data: {:?}", err);
}
});
}));
action_sender
}

Expand Down
18 changes: 11 additions & 7 deletions components/script/dom/bluetoothadvertisingevent.rs
Expand Up @@ -55,13 +55,17 @@ impl BluetoothAdvertisingEvent {
txPower: Option<i8>,
rssi: Option<i8>)
-> DomRoot<BluetoothAdvertisingEvent> {
let ev = reflect_dom_object(box BluetoothAdvertisingEvent::new_inherited(device,
name,
appearance,
txPower,
rssi),
global,
BluetoothAdvertisingEventBinding::Wrap);
let ev = reflect_dom_object(
Box::new(BluetoothAdvertisingEvent::new_inherited(
device,
name,
appearance,
txPower,
rssi
)),
global,
BluetoothAdvertisingEventBinding::Wrap
);
{
let event = ev.upcast::<Event>();
event.init_event(type_, bool::from(bubbles), bool::from(cancelable));
Expand Down
28 changes: 16 additions & 12 deletions components/script/dom/bluetoothcharacteristicproperties.rs
Expand Up @@ -61,19 +61,23 @@ impl BluetoothCharacteristicProperties {
reliableWrite: bool,
writableAuxiliaries: bool)
-> DomRoot<BluetoothCharacteristicProperties> {
reflect_dom_object(box BluetoothCharacteristicProperties::new_inherited(broadcast,
read,
writeWithoutResponse,
write,
notify,
indicate,
authenticatedSignedWrites,
reliableWrite,
writableAuxiliaries),
global,
BluetoothCharacteristicPropertiesBinding::Wrap)
}
reflect_dom_object(
Box::new(BluetoothCharacteristicProperties::new_inherited(
broadcast,
read,
writeWithoutResponse,
write,
notify,
indicate,
authenticatedSignedWrites,
reliableWrite,
writableAuxiliaries
)),
global,
BluetoothCharacteristicPropertiesBinding::Wrap
)
}
}

impl BluetoothCharacteristicPropertiesMethods for BluetoothCharacteristicProperties {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-broadcast
Expand Down
4 changes: 1 addition & 3 deletions components/script/dom/bluetoothdevice.rs
Expand Up @@ -66,9 +66,7 @@ impl BluetoothDevice {
name: Option<DOMString>,
context: &Bluetooth)
-> DomRoot<BluetoothDevice> {
reflect_dom_object(box BluetoothDevice::new_inherited(id,
name,
context),
reflect_dom_object(Box::new(BluetoothDevice::new_inherited(id, name, context)),
global,
BluetoothDeviceBinding::Wrap)
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bluetoothpermissionresult.rs
Expand Up @@ -41,7 +41,7 @@ impl BluetoothPermissionResult {
}

pub fn new(global: &GlobalScope, status: &PermissionStatus) -> DomRoot<BluetoothPermissionResult> {
reflect_dom_object(box BluetoothPermissionResult::new_inherited(status),
reflect_dom_object(Box::new(BluetoothPermissionResult::new_inherited(status)),
global,
BluetoothPermissionResultBinding::Wrap)
}
Expand Down
13 changes: 7 additions & 6 deletions components/script/dom/bluetoothremotegattcharacteristic.rs
Expand Up @@ -65,12 +65,13 @@ impl BluetoothRemoteGATTCharacteristic {
properties: &BluetoothCharacteristicProperties,
instanceID: String)
-> DomRoot<BluetoothRemoteGATTCharacteristic> {
reflect_dom_object(box BluetoothRemoteGATTCharacteristic::new_inherited(service,
uuid,
properties,
instanceID),
global,
BluetoothRemoteGATTCharacteristicBinding::Wrap)
reflect_dom_object(
Box::new(BluetoothRemoteGATTCharacteristic::new_inherited(
service, uuid, properties, instanceID
)),
global,
BluetoothRemoteGATTCharacteristicBinding::Wrap
)
}

fn get_bluetooth_thread(&self) -> IpcSender<BluetoothRequest> {
Expand Down
12 changes: 7 additions & 5 deletions components/script/dom/bluetoothremotegattdescriptor.rs
Expand Up @@ -52,11 +52,13 @@ impl BluetoothRemoteGATTDescriptor {
uuid: DOMString,
instanceID: String)
-> DomRoot<BluetoothRemoteGATTDescriptor>{
reflect_dom_object(box BluetoothRemoteGATTDescriptor::new_inherited(characteristic,
uuid,
instanceID),
global,
BluetoothRemoteGATTDescriptorBinding::Wrap)
reflect_dom_object(
Box::new(BluetoothRemoteGATTDescriptor::new_inherited(
characteristic, uuid, instanceID
)),
global,
BluetoothRemoteGATTDescriptorBinding::Wrap
)
}

fn get_bluetooth_thread(&self) -> IpcSender<BluetoothRequest> {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bluetoothremotegattserver.rs
Expand Up @@ -38,7 +38,7 @@ impl BluetoothRemoteGATTServer {
}

pub fn new(global: &GlobalScope, device: &BluetoothDevice) -> DomRoot<BluetoothRemoteGATTServer> {
reflect_dom_object(box BluetoothRemoteGATTServer::new_inherited(device),
reflect_dom_object(Box::new(BluetoothRemoteGATTServer::new_inherited(device)),
global,
BluetoothRemoteGATTServerBinding::Wrap)
}
Expand Down
13 changes: 7 additions & 6 deletions components/script/dom/bluetoothremotegattservice.rs
Expand Up @@ -50,12 +50,13 @@ impl BluetoothRemoteGATTService {
isPrimary: bool,
instanceID: String)
-> DomRoot<BluetoothRemoteGATTService> {
reflect_dom_object(box BluetoothRemoteGATTService::new_inherited(device,
uuid,
isPrimary,
instanceID),
global,
BluetoothRemoteGATTServiceBinding::Wrap)
reflect_dom_object(
Box::new(BluetoothRemoteGATTService::new_inherited(
device, uuid, isPrimary, instanceID
)),
global,
BluetoothRemoteGATTServiceBinding::Wrap
)
}

fn get_instance_id(&self) -> String {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/canvasgradient.rs
Expand Up @@ -40,7 +40,7 @@ impl CanvasGradient {
}

pub fn new(global: &GlobalScope, style: CanvasGradientStyle) -> DomRoot<CanvasGradient> {
reflect_dom_object(box CanvasGradient::new_inherited(style),
reflect_dom_object(Box::new(CanvasGradient::new_inherited(style)),
global,
CanvasGradientBinding::Wrap)
}
Expand Down
11 changes: 7 additions & 4 deletions components/script/dom/canvaspattern.rs
Expand Up @@ -50,10 +50,13 @@ impl CanvasPattern {
repeat: RepetitionStyle,
origin_clean: bool)
-> DomRoot<CanvasPattern> {
reflect_dom_object(box CanvasPattern::new_inherited(surface_data, surface_size,
repeat, origin_clean),
global,
CanvasPatternBinding::Wrap)
reflect_dom_object(
Box::new(CanvasPattern::new_inherited(
surface_data, surface_size, repeat, origin_clean
)),
global,
CanvasPatternBinding::Wrap
)
}
pub fn origin_is_clean(&self) -> bool {
self.origin_clean
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -155,7 +155,9 @@ impl CanvasRenderingContext2D {
let window = window_from_node(canvas);
let image_cache = window.image_cache();
let base_url = window.get_url();
let boxed = box CanvasRenderingContext2D::new_inherited(global, Some(canvas), image_cache, base_url, size);
let boxed = Box::new(CanvasRenderingContext2D::new_inherited(
global, Some(canvas), image_cache, base_url, size
));
reflect_dom_object(boxed, global, CanvasRenderingContext2DBinding::Wrap)
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/client.rs
Expand Up @@ -36,7 +36,7 @@ impl Client {
}

pub fn new(window: &Window) -> DomRoot<Client> {
reflect_dom_object(box Client::new_inherited(window.get_url()),
reflect_dom_object(Box::new(Client::new_inherited(window.get_url())),
window,
Wrap)
}
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/closeevent.rs
Expand Up @@ -34,7 +34,7 @@ impl CloseEvent {
}

pub fn new_uninitialized(global: &GlobalScope) -> DomRoot<CloseEvent> {
reflect_dom_object(box CloseEvent::new_inherited(false, 0, DOMString::new()),
reflect_dom_object(Box::new(CloseEvent::new_inherited(false, 0, DOMString::new())),
global,
CloseEventBinding::Wrap)
}
Expand All @@ -47,7 +47,7 @@ impl CloseEvent {
code: u16,
reason: DOMString)
-> DomRoot<CloseEvent> {
let event = box CloseEvent::new_inherited(wasClean, code, reason);
let event = Box::new(CloseEvent::new_inherited(wasClean, code, reason));
let ev = reflect_dom_object(event, global, CloseEventBinding::Wrap);
{
let event = ev.upcast::<Event>();
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/comment.rs
Expand Up @@ -27,7 +27,7 @@ impl Comment {
}

pub fn new(text: DOMString, document: &Document) -> DomRoot<Comment> {
Node::reflect_node(box Comment::new_inherited(text, document),
Node::reflect_node(Box::new(Comment::new_inherited(text, document)),
document,
CommentBinding::Wrap)
}
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/compositionevent.rs
Expand Up @@ -26,10 +26,10 @@ impl CompositionEvent {
view: Option<&Window>,
detail: i32,
data: DOMString) -> DomRoot<CompositionEvent> {
let ev = reflect_dom_object(box CompositionEvent {
let ev = reflect_dom_object(Box::new(CompositionEvent {
uievent: UIEvent::new_inherited(),
data: data,
},
}),
window,
CompositionEventBinding::Wrap);
ev.uievent.InitUIEvent(type_, can_bubble, cancelable, view, detail);
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/crypto.rs
Expand Up @@ -34,7 +34,7 @@ impl Crypto {
}

pub fn new(global: &GlobalScope) -> DomRoot<Crypto> {
reflect_dom_object(box Crypto::new_inherited(), global, CryptoBinding::Wrap)
reflect_dom_object(Box::new(Crypto::new_inherited()), global, CryptoBinding::Wrap)
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/cssfontfacerule.rs
Expand Up @@ -33,7 +33,7 @@ impl CSSFontFaceRule {
#[allow(unrooted_must_root)]
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
fontfacerule: Arc<Locked<FontFaceRule>>) -> DomRoot<CSSFontFaceRule> {
reflect_dom_object(box CSSFontFaceRule::new_inherited(parent_stylesheet, fontfacerule),
reflect_dom_object(Box::new(CSSFontFaceRule::new_inherited(parent_stylesheet, fontfacerule)),
window,
CSSFontFaceRuleBinding::Wrap)
}
Expand Down

0 comments on commit aa15dc2

Please sign in to comment.