Repository: servo/servo
File: components/script/dom/html/htmllinkelement.rs (Rust)

Code before:
    }

    pub(crate) fn new(
        local_name: LocalName,
        prefix: Option<Prefix>,
        document: &Document,
        proto: Option<HandleObject>,
        creator: ElementCreator,
        can_gc: CanGc,
    ) -> DomRoot<HTMLLinkElement> {
        Node::reflect_node_with_proto(
            Box::new(HTMLLinkElement::new_inherited(
                local_name, prefix, document, creator,
            )),
            document,
            proto,
            can_gc,
        )
    }

    pub(crate) fn get_request_generation_id(&self) -> RequestGenerationId {
        self.request_generation_id.get()
    }

    fn remove_stylesheet(&self) {
        if let Some(s) = self.stylesheet.borrow_mut().take() {
            let owner = self.stylesheet_list_owner();
            owner.remove_stylesheet(StylesheetSource::Element(Dom::from_ref(self.upcast())), &s);
            self.clean_stylesheet_ownership();
            owner.invalidate_stylesheets();
        }
    }

    // FIXME(emilio): These methods are duplicated with
    // HTMLStyleElement::set_stylesheet.
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    pub(crate) fn set_stylesheet(&self, new_stylesheet: Arc<Stylesheet>) {
        let owner = self.stylesheet_list_owner();
        if let Some(old_stylesheet) = self.stylesheet.borrow_mut().replace(new_stylesheet.clone()) {
            owner.remove_stylesheet(
                StylesheetSource::Element(Dom::from_ref(self.upcast())),
                &old_stylesheet,
            );
        }
        owner.add_owned_stylesheet(self.upcast(), new_stylesheet);
    }

    pub(crate) fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> {
        self.stylesheet.borrow().clone()
    }


Review comment (suggestion):
Nit:


```suggestion
        if let Some(stylesheet) = self.stylesheet.borrow_mut().take() {
```

Code after:
    }

    pub(crate) fn new(
        local_name: LocalName,
        prefix: Option<Prefix>,
        document: &Document,
        proto: Option<HandleObject>,
        creator: ElementCreator,
        can_gc: CanGc,
    ) -> DomRoot<HTMLLinkElement> {
        Node::reflect_node_with_proto(
            Box::new(HTMLLinkElement::new_inherited(
                local_name, prefix, document, creator,
            )),
            document,
            proto,
            can_gc,
        )
    }

    pub(crate) fn get_request_generation_id(&self) -> RequestGenerationId {
        self.request_generation_id.get()
    }

    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    fn remove_stylesheet(&self) {
        if let Some(stylesheet) = self.stylesheet.borrow_mut().take() {
            let owner = self.stylesheet_list_owner();
            owner.remove_stylesheet(
                StylesheetSource::Element(Dom::from_ref(self.upcast())),
                &stylesheet,
            );
            self.clean_stylesheet_ownership();
            owner.invalidate_stylesheets();
        }
    }

    // FIXME(emilio): These methods are duplicated with
    // HTMLStyleElement::set_stylesheet.
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    pub(crate) fn set_stylesheet(&self, new_stylesheet: Arc<Stylesheet>) {
        let owner = self.stylesheet_list_owner();
        if let Some(old_stylesheet) = self.stylesheet.borrow_mut().replace(new_stylesheet.clone()) {
            owner.remove_stylesheet(
                StylesheetSource::Element(Dom::from_ref(self.upcast())),
                &old_stylesheet,
            );
        }
        owner.add_owned_stylesheet(self.upcast(), new_stylesheet);
    }