style: Use union to wrap different shape-like types. r=xidorn

1. We will add more shape-like types in the future, so it's better to
   use union to reduce the memory usage.
2. Those shape-like types are mutual exclusive, so we could use union to
   wrap them.

Differential Revision: https://phabricator.services.mozilla.com/D2746
This commit is contained in:
Boris Chiou 2018-08-07 07:56:01 +00:00 committed by Emilio Cobos Álvarez
parent ad83faa745
commit c87668fcd5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 5 additions and 5 deletions

View file

@ -659,7 +659,7 @@ pub mod basic_shape {
StyleShapeSourceType::None => Some(ShapeSource::None), StyleShapeSourceType::None => Some(ShapeSource::None),
StyleShapeSourceType::Box => Some(ShapeSource::Box(self.mReferenceBox.into())), StyleShapeSourceType::Box => Some(ShapeSource::Box(self.mReferenceBox.into())),
StyleShapeSourceType::Shape => { StyleShapeSourceType::Shape => {
let other_shape = unsafe { &*self.mBasicShape.mPtr }; let other_shape = unsafe { &*self.__bindgen_anon_1.mBasicShape.as_ref().mPtr };
let shape = other_shape.into(); let shape = other_shape.into();
let reference_box = if self.mReferenceBox == StyleGeometryBox::NoBox { let reference_box = if self.mReferenceBox == StyleGeometryBox::NoBox {
None None
@ -677,7 +677,7 @@ pub mod basic_shape {
fn from(other: &'a StyleShapeSource) -> Self { fn from(other: &'a StyleShapeSource) -> Self {
match other.mType { match other.mType {
StyleShapeSourceType::URL => unsafe { StyleShapeSourceType::URL => unsafe {
let shape_image = &*other.mShapeImage.mPtr; let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr;
let other_url = RefPtr::new(*shape_image.__bindgen_anon_1.mURLValue.as_ref()); let other_url = RefPtr::new(*shape_image.__bindgen_anon_1.mURLValue.as_ref());
let url = ComputedUrl::from_url_value(other_url); let url = ComputedUrl::from_url_value(other_url);
ShapeSource::ImageOrUrl(url) ShapeSource::ImageOrUrl(url)
@ -699,7 +699,7 @@ pub mod basic_shape {
unreachable!("FloatAreaShape doesn't support URL!"); unreachable!("FloatAreaShape doesn't support URL!");
}, },
StyleShapeSourceType::Image => unsafe { StyleShapeSourceType::Image => unsafe {
let shape_image = &*other.mShapeImage.mPtr; let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr;
let image = shape_image.into_image().expect("Cannot convert to Image"); let image = shape_image.into_image().expect("Cannot convert to Image");
ShapeSource::ImageOrUrl(image) ShapeSource::ImageOrUrl(image)
}, },

View file

@ -4960,7 +4960,7 @@ fn static_assert() {
ShapeSource::ImageOrUrl(image) => { ShapeSource::ImageOrUrl(image) => {
unsafe { unsafe {
bindings::Gecko_NewShapeImage(${ident}); bindings::Gecko_NewShapeImage(${ident});
let style_image = &mut *${ident}.mShapeImage.mPtr; let style_image = &mut *${ident}.__bindgen_anon_1.mShapeImage.as_mut().mPtr;
style_image.set(image); style_image.set(image);
} }
} }
@ -4980,7 +4980,7 @@ fn static_assert() {
// Create StyleBasicShape in StyleShapeSource. mReferenceBox and mType // Create StyleBasicShape in StyleShapeSource. mReferenceBox and mType
// will be set manually later. // will be set manually later.
Gecko_NewBasicShape(${ident}, basic_shape_type); Gecko_NewBasicShape(${ident}, basic_shape_type);
&mut *${ident}.mBasicShape.mPtr &mut *${ident}.__bindgen_anon_1.mBasicShape.as_mut().mPtr
} }
} }
match servo_shape { match servo_shape {