Repository: alacritty/alacritty
File: alacritty_terminal/src/term/cell.rs (Rust)

Code before:
    pub fn zerowidth(&self) -> Option<&[char]> {
        self.extra.as_ref().map(|extra| extra.zerowidth.as_slice())
    }

    /// Write a new zerowidth character to this cell.
    #[inline]
    pub(crate) fn push_zerowidth(&mut self, character: char) {
        self.init_extra();

        let extra = Arc::make_mut(self.extra.as_mut().unwrap());
        extra.zerowidth.push(character);
    }

    /// Remove all wide char data from a cell.
    #[inline(never)]
    pub(crate) fn clear_wide(&mut self) {
        self.flags.remove(Flags::WIDE_CHAR);
        self.extra = None;
        self.c = ' ';
    }

    /// Set underline color on the cell.
    pub(crate) fn set_underline_color(&mut self, color: Option<Color>) {
        // If we reset color and we don't have zerowidth we should drop extra storage.
        if color.is_none()
            && self.extra.as_ref().map(|extra| !extra.zerowidth.is_empty()) != Some(false)
        {
            self.extra = None;
            return;
        }

        self.init_extra();

        let extra = Arc::make_mut(self.extra.as_mut().unwrap());
        extra.underline_color = color;
    }

    /// Initializes extra storage if there's none.
    #[inline]
    fn init_extra(&mut self) {
        if self.extra.is_none() {
            self.extra = Some(Arc::new(Default::default()));
        }
    }

    /// Underline color stored in this cell.
    #[inline]
    pub fn undreline_color(&self) -> Option<Color> {
        self.extra.as_ref()?.underline_color
    }
}

Review comment (suggestion):
```suggestion
            && self.extra.as_ref().map_or(true, |extra| !extra.zerowidth.is_empty())
```

Code after:
        self.extra.as_ref().map(|extra| extra.zerowidth.as_slice())
    }

    /// Write a new zerowidth character to this cell.
    #[inline]
    pub fn push_zerowidth(&mut self, character: char) {
        let extra = self.extra.get_or_insert(Default::default());
        Arc::make_mut(extra).zerowidth.push(character);
    }

    /// Remove all wide char data from a cell.
    #[inline(never)]
    pub fn clear_wide(&mut self) {
        self.flags.remove(Flags::WIDE_CHAR);
        if let Some(extra) = self.extra.as_mut() {
            Arc::make_mut(extra).zerowidth = Vec::new();
        }
        self.c = ' ';
    }

    /// Set underline color on the cell.
    pub fn set_underline_color(&mut self, color: Option<Color>) {
        // If we reset color and we don't have zerowidth we should drop extra storage.
        if color.is_none() && self.extra.as_ref().map_or(true, |extra| !extra.zerowidth.is_empty())
        {
            self.extra = None;
            return;
        }

        let extra = self.extra.get_or_insert(Default::default());
        Arc::make_mut(extra).underline_color = color;
    }

    /// Underline color stored in this cell.
    #[inline]
    pub fn underline_color(&self) -> Option<Color> {
        self.extra.as_ref()?.underline_color
    }
}

impl GridCell for Cell {
    #[inline]
    fn is_empty(&self) -> bool {
        (self.c == ' ' || self.c == '\t')
            && self.bg == Color::Named(NamedColor::Background)
            && self.fg == Color::Named(NamedColor::Foreground)
            && !self.flags.intersects(
                Flags::INVERSE
                    | Flags::ALL_UNDERLINES
                    | Flags::STRIKEOUT
                    | Flags::WRAPLINE