mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Stylo: replace uses of mem::uninitialized with MaybeUninit
MozReview-Commit-ID: KGhYL6DJRaR
This commit is contained in:
parent
00b3fb49c4
commit
17ec774a49
9 changed files with 60 additions and 68 deletions
|
@ -44,9 +44,9 @@ use crate::properties::computed_value_flags::*;
|
|||
use crate::properties::longhands;
|
||||
use crate::rule_tree::StrongRuleNode;
|
||||
use crate::selector_parser::PseudoElement;
|
||||
use servo_arc::{Arc, RawOffsetArc};
|
||||
use servo_arc::{Arc, RawOffsetArc, UniqueArc};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::{forget, uninitialized, zeroed, ManuallyDrop};
|
||||
use std::mem::{forget, zeroed, ManuallyDrop};
|
||||
use std::{cmp, ops, ptr};
|
||||
use crate::values::{self, CustomIdent, Either, KeyframesName, None_};
|
||||
use crate::values::computed::{Percentage, TransitionProperty};
|
||||
|
@ -210,19 +210,18 @@ impl ComputedValuesInner {
|
|||
Some(p) => p.pseudo_type(),
|
||||
None => structs::PseudoStyleType::NotPseudo,
|
||||
};
|
||||
let arc = unsafe {
|
||||
let arc: Arc<ComputedValues> = Arc::new(uninitialized());
|
||||
unsafe {
|
||||
let mut arc = UniqueArc::<ComputedValues>::new_uninit();
|
||||
bindings::Gecko_ComputedStyle_Init(
|
||||
&arc.0 as *const _ as *mut _,
|
||||
&mut (*arc.as_mut_ptr()).0,
|
||||
&self,
|
||||
pseudo_ty,
|
||||
);
|
||||
// We're simulating a move by having C++ do a memcpy and then forgetting
|
||||
// We're simulating move semantics by having C++ do a memcpy and then forgetting
|
||||
// it on this end.
|
||||
forget(self);
|
||||
arc
|
||||
};
|
||||
arc
|
||||
UniqueArc::assume_init(arc).shareable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::properties::LonghandId;
|
|||
use servo_arc::Arc;
|
||||
use smallvec::SmallVec;
|
||||
use std::ptr;
|
||||
use std::mem::{self, ManuallyDrop};
|
||||
use std::mem;
|
||||
use crate::hash::FxHashMap;
|
||||
use super::ComputedValues;
|
||||
use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||
|
@ -252,12 +252,12 @@ impl Clone for AnimationValue {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
let mut out = mem::uninitialized();
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut CopyVariants,
|
||||
out.as_mut_ptr() as *mut CopyVariants,
|
||||
*(self as *const _ as *const CopyVariants),
|
||||
);
|
||||
return out;
|
||||
return out.assume_init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,15 +269,15 @@ impl Clone for AnimationValue {
|
|||
${props[0].camel_case}(value.clone())
|
||||
% else:
|
||||
unsafe {
|
||||
let mut out = ManuallyDrop::new(mem::uninitialized());
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut AnimationValueVariantRepr<${ty}>,
|
||||
out.as_mut_ptr() as *mut AnimationValueVariantRepr<${ty}>,
|
||||
AnimationValueVariantRepr {
|
||||
tag: *(self as *const _ as *const u16),
|
||||
value: value.clone(),
|
||||
},
|
||||
);
|
||||
ManuallyDrop::into_inner(out)
|
||||
out.assume_init()
|
||||
}
|
||||
% endif
|
||||
}
|
||||
|
@ -356,15 +356,15 @@ impl AnimationValue {
|
|||
PropertyDeclaration::${props[0].camel_case}(value)
|
||||
% else:
|
||||
unsafe {
|
||||
let mut out = mem::uninitialized();
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut PropertyDeclarationVariantRepr<${specified}>,
|
||||
out.as_mut_ptr() as *mut PropertyDeclarationVariantRepr<${specified}>,
|
||||
PropertyDeclarationVariantRepr {
|
||||
tag: *(self as *const _ as *const u16),
|
||||
value,
|
||||
},
|
||||
);
|
||||
out
|
||||
out.assume_init()
|
||||
}
|
||||
% endif
|
||||
}
|
||||
|
@ -424,15 +424,15 @@ impl AnimationValue {
|
|||
% endif
|
||||
|
||||
unsafe {
|
||||
let mut out = mem::uninitialized();
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut AnimationValueVariantRepr<${ty}>,
|
||||
out.as_mut_ptr() as *mut AnimationValueVariantRepr<${ty}>,
|
||||
AnimationValueVariantRepr {
|
||||
tag: longhand_id.to_physical(context.builder.writing_mode) as u16,
|
||||
value,
|
||||
},
|
||||
);
|
||||
out
|
||||
out.assume_init()
|
||||
}
|
||||
}
|
||||
% endfor
|
||||
|
@ -579,15 +579,15 @@ impl Animate for AnimationValue {
|
|||
let value = this.animate(&other_repr.value, procedure)?;
|
||||
% endif
|
||||
|
||||
let mut out = mem::uninitialized();
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut AnimationValueVariantRepr<${ty}>,
|
||||
out.as_mut_ptr() as *mut AnimationValueVariantRepr<${ty}>,
|
||||
AnimationValueVariantRepr {
|
||||
tag: this_tag,
|
||||
value,
|
||||
},
|
||||
);
|
||||
out
|
||||
out.assume_init()
|
||||
}
|
||||
% endfor
|
||||
${" |\n".join("{}(void)".format(prop.camel_case) for prop in unanimated)} => {
|
||||
|
|
|
@ -390,15 +390,16 @@ ${helpers.predefined_type(
|
|||
% endfor
|
||||
};
|
||||
|
||||
let mut system: nsFont = unsafe { mem::uninitialized() };
|
||||
unsafe {
|
||||
let mut system = mem::MaybeUninit::<nsFont>::uninit();
|
||||
let system = unsafe {
|
||||
bindings::Gecko_nsFont_InitSystem(
|
||||
&mut system,
|
||||
system.as_mut_ptr(),
|
||||
id as i32,
|
||||
cx.style().get_font().gecko(),
|
||||
cx.device().document()
|
||||
)
|
||||
}
|
||||
);
|
||||
&mut *system.as_mut_ptr()
|
||||
};
|
||||
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||
let font_stretch = FontStretch(NonNegative(Percentage(unsafe {
|
||||
bindings::Gecko_FontStretch_ToFloat(system.stretch)
|
||||
|
@ -436,7 +437,7 @@ ${helpers.predefined_type(
|
|||
system_font: *self,
|
||||
default_font_type: system.fontlist.mDefaultFontType,
|
||||
};
|
||||
unsafe { bindings::Gecko_nsFont_Destroy(&mut system); }
|
||||
unsafe { bindings::Gecko_nsFont_Destroy(system); }
|
||||
ret
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use servo_arc::{Arc, UniqueArc};
|
|||
use std::borrow::Cow;
|
||||
use std::{ops, ptr};
|
||||
use std::fmt::{self, Write};
|
||||
use std::mem::{self, ManuallyDrop};
|
||||
use std::mem;
|
||||
|
||||
use cssparser::{Parser, RGBA, TokenSerializationType};
|
||||
use cssparser::ParserInput;
|
||||
|
@ -294,12 +294,12 @@ impl Clone for PropertyDeclaration {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
let mut out = mem::uninitialized();
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut CopyVariants,
|
||||
out.as_mut_ptr() as *mut CopyVariants,
|
||||
*(self as *const _ as *const CopyVariants),
|
||||
);
|
||||
return out;
|
||||
return out.assume_init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,15 +333,15 @@ impl Clone for PropertyDeclaration {
|
|||
% else:
|
||||
${" |\n".join("{}(ref value)".format(v["name"]) for v in vs)} => {
|
||||
unsafe {
|
||||
let mut out = ManuallyDrop::new(mem::uninitialized());
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
ptr::write(
|
||||
&mut out as *mut _ as *mut PropertyDeclarationVariantRepr<${ty}>,
|
||||
out.as_mut_ptr() as *mut PropertyDeclarationVariantRepr<${ty}>,
|
||||
PropertyDeclarationVariantRepr {
|
||||
tag: *(self as *const _ as *const u16),
|
||||
value: value.clone(),
|
||||
},
|
||||
);
|
||||
ManuallyDrop::into_inner(out)
|
||||
out.assume_init()
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue