Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of unstable box syntax. #18900

Merged
merged 1 commit into from Oct 16, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Remove use of unstable box syntax.

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
commit aa15dc269f41503d81ad44cd7e85d69e6f4aeac7
@@ -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(),
}
})
}
}

@@ -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(),
}
})
}
}

@@ -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]
@@ -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)
}
@@ -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));
@@ -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)
}

@@ -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);
}
@@ -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;
@@ -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)
}

@@ -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)
}
@@ -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,
@@ -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
}

@@ -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));
@@ -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
@@ -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)
}
@@ -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)
}
@@ -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> {
@@ -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> {
@@ -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)
}
@@ -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 {
@@ -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)
}
@@ -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
@@ -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)
}

@@ -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)
}
@@ -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)
}
@@ -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>();
@@ -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)
}
@@ -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);
@@ -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)
}
}

@@ -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)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.