Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created March 29, 2017 08:51
Show Gist options
  • Save mitsuhiko/474725b6872853bf14a07d0f788258a9 to your computer and use it in GitHub Desktop.
Save mitsuhiko/474725b6872853bf14a07d0f788258a9 to your computer and use it in GitHub Desktop.
fn get_nsmap_mut(&mut self) -> &mut NamespaceMap {
if self.nsmap.is_none() {
self.nsmap = Some(Rc::new(NamespaceMap::new()));
}
{
let nsmap_copy = {
let nsmap = self.nsmap.as_mut().unwrap();
if Rc::strong_count(nsmap) == 1 {
return Rc::get_mut(nsmap).unwrap()
}
(**nsmap).clone()
};
self.nsmap = Some(Rc::new(nsmap_copy));
}
Rc::get_mut(self.nsmap.as_mut().unwrap()).unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment