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

Code before:
    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
    }
}

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
                    | Flags::WIDE_CHAR_SPACER
                    | Flags::LEADING_WIDE_CHAR_SPACER,
            )
            && self.extra.as_ref().map(|extra| extra.zerowidth.is_empty()) != Some(false)
    }

    #[inline]
    fn flags(&self) -> &Flags {
        &self.flags
    }

Review comment (suggestion):
```suggestion
    pub fn underline_color(&self) -> Option<Color> {
```

Code after:
        // 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
                    | Flags::WIDE_CHAR_SPACER
                    | Flags::LEADING_WIDE_CHAR_SPACER,
            )
            && self.extra.as_ref().map(|extra| extra.zerowidth.is_empty()) != Some(false)
    }

    #[inline]
    fn flags(&self) -> &Flags {
        &self.flags
    }

    #[inline]
    fn flags_mut(&mut self) -> &mut Flags {
        &mut self.flags
    }

    #[inline]
    fn reset(&mut self, template: &Self) {
        *self = Cell { bg: template.bg, ..Cell::default() };
    }
}