aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2017-05-02 11:08:31 -0700
committerBobby Holley <bobbyholley@gmail.com>2017-05-02 17:35:45 -0700
commit7dba36ed73de4ea00a8bd2e7690312f3e51440a9 (patch)
treede7847ba2839933b1425674be19e54767c3c5d46
parent7b0679848b177ead3a87171d0224e05ecadd8006 (diff)
downloadservo-7dba36ed73de4ea00a8bd2e7690312f3e51440a9.tar.gz
servo-7dba36ed73de4ea00a8bd2e7690312f3e51440a9.zip
Make StyleBuilder more efficient using stylearc.
MozReview-Commit-ID: 8wSsYPEmYE4
-rw-r--r--components/style/properties/properties.mako.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs
index 83ca3e3d4fb..ff2361fb792 100644
--- a/components/style/properties/properties.mako.rs
+++ b/components/style/properties/properties.mako.rs
@@ -2056,7 +2056,7 @@ pub enum StyleStructRef<'a, T: 'a> {
/// A borrowed struct from the parent, for example, for inheriting style.
Borrowed(&'a Arc<T>),
/// An owned struct, that we've already mutated.
- Owned(T),
+ Owned(Arc<T>),
}
impl<'a, T: 'a> StyleStructRef<'a, T>
@@ -2066,11 +2066,11 @@ impl<'a, T: 'a> StyleStructRef<'a, T>
/// borrowed value, or returning the owned one.
pub fn mutate(&mut self) -> &mut T {
if let StyleStructRef::Borrowed(v) = *self {
- *self = StyleStructRef::Owned((**v).clone());
+ *self = StyleStructRef::Owned(Arc::new((**v).clone()));
}
match *self {
- StyleStructRef::Owned(ref mut v) => v,
+ StyleStructRef::Owned(ref mut v) => Arc::get_mut(v).unwrap(),
StyleStructRef::Borrowed(..) => unreachable!(),
}
}
@@ -2079,7 +2079,7 @@ impl<'a, T: 'a> StyleStructRef<'a, T>
/// hasn't been mutated.
pub fn get_if_mutated(&mut self) -> Option<<&mut T> {
match *self {
- StyleStructRef::Owned(ref mut v) => Some(v),
+ StyleStructRef::Owned(ref mut v) => Some(Arc::get_mut(v).unwrap()),
StyleStructRef::Borrowed(..) => None,
}
}
@@ -2088,7 +2088,7 @@ impl<'a, T: 'a> StyleStructRef<'a, T>
/// appropriate.
pub fn build(self) -> Arc<T> {
match self {
- StyleStructRef::Owned(v) => Arc::new(v),
+ StyleStructRef::Owned(v) => v,
StyleStructRef::Borrowed(v) => v.clone(),
}
}
@@ -2099,7 +2099,7 @@ impl<'a, T: 'a> Deref for StyleStructRef<'a, T> {
fn deref(&self) -> &T {
match *self {
- StyleStructRef::Owned(ref v) => v,
+ StyleStructRef::Owned(ref v) => &**v,
StyleStructRef::Borrowed(v) => &**v,
}
}