rollup merge of #19225: reem/any-unnecessary-transmute-copy
transmute_copy is no longer needed and is just slow.
This commit is contained in:
@@ -15,7 +15,6 @@ use core::clone::Clone;
|
|||||||
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::intrinsics;
|
|
||||||
use core::kinds::Sized;
|
use core::kinds::Sized;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
@@ -104,17 +103,14 @@ pub trait BoxAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl BoxAny for Box<Any+'static> {
|
impl BoxAny for Box<Any> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any+'static>> {
|
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Get the raw representation of the trait object
|
// Get the raw representation of the trait object
|
||||||
let to: TraitObject =
|
let to: TraitObject =
|
||||||
*mem::transmute::<&Box<Any>, &TraitObject>(&self);
|
mem::transmute::<Box<Any>, TraitObject>(self);
|
||||||
|
|
||||||
// Prevent destructor on self being run
|
|
||||||
intrinsics::forget(self);
|
|
||||||
|
|
||||||
// Extract the data pointer
|
// Extract the data pointer
|
||||||
Ok(mem::transmute(to.data))
|
Ok(mem::transmute(to.data))
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
#![stable]
|
#![stable]
|
||||||
|
|
||||||
use mem::{transmute, transmute_copy};
|
use mem::{transmute};
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use raw::TraitObject;
|
use raw::TraitObject;
|
||||||
use intrinsics::TypeId;
|
use intrinsics::TypeId;
|
||||||
@@ -134,7 +134,7 @@ impl<'a> AnyRefExt<'a> for &'a Any {
|
|||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Get the raw representation of the trait object
|
// Get the raw representation of the trait object
|
||||||
let to: TraitObject = transmute_copy(&self);
|
let to: TraitObject = transmute(self);
|
||||||
|
|
||||||
// Extract the data pointer
|
// Extract the data pointer
|
||||||
Some(transmute(to.data))
|
Some(transmute(to.data))
|
||||||
@@ -162,7 +162,7 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any {
|
|||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Get the raw representation of the trait object
|
// Get the raw representation of the trait object
|
||||||
let to: TraitObject = transmute_copy(&self);
|
let to: TraitObject = transmute(self);
|
||||||
|
|
||||||
// Extract the data pointer
|
// Extract the data pointer
|
||||||
Some(transmute(to.data))
|
Some(transmute(to.data))
|
||||||
|
|||||||
Reference in New Issue
Block a user