Repository: alacritty/alacritty
File: alacritty/src/config/window.rs (Rust)

Code before:
            dimensions: Default::default(),
        }
    }
}

impl WindowConfig {
    #[inline]
    pub fn dimensions(&self) -> Option<Dimensions> {
        // Warn if one of columns, lines is non-zero but not both
        if (self.dimensions.lines != 0) ^ (self.dimensions.columns.0 != 0) {
            let (zero_key, key, value) = match self.dimensions.lines != 0 {
                true => ("columns", "lines", self.dimensions.lines),
                false => ("lines", "columns", self.dimensions.columns.0),
            };

            warn!(
                target: LOG_TARGET_CONFIG,
                "Both lines and columns must be non-zero for window.dimensions to take effect. \
                Configured value of {} is 0 while that of {} is {}",
                zero_key,
                key,
                value,
            );
        }

        if (self.dimensions.lines != 0) && (self.dimensions.columns.0 != 0) {
            Some(self.dimensions)
        } else {
            None
        }
    }

    #[inline]
    pub fn padding(&self, scale_factor: f64) -> (f32, f32) {
        let padding_x = (f32::from(self.padding.x) * scale_factor as f32).floor();
        let padding_y = (f32::from(self.padding.y) * scale_factor as f32).floor();
        (padding_x, padding_y)
    }

    #[inline]
    pub fn fullscreen(&self) -> Option<Fullscreen> {
        if self.startup_mode == StartupMode::Fullscreen {
            Some(Fullscreen::Borderless(None))
        } else {
            None
        }
    }

    #[inline]
    pub fn maximized(&self) -> bool {
        self.startup_mode == StartupMode::Maximized

Review comment (suggestion):
You check the same stuff 5 times. At that point it would be much easier to just assign it to a descriptive variable and check that instead.

It also is entirely pointless to check for warnings if we know that both dimensions and columns are `!= 0` anyway. So this should really be an `if -> else if -> else`.

Code after:
            dimensions: Default::default(),
        }
    }
}

impl WindowConfig {
    #[inline]
    pub fn dimensions(&self) -> Option<Dimensions> {
        let (lines, columns) = (self.dimensions.lines, self.dimensions.columns.0);
        let (lines_is_non_zero, columns_is_non_zero) = (lines != 0, columns != 0);

        if lines_is_non_zero && columns_is_non_zero {
            // Return dimensions if both `lines` and `columns` are non-zero.
            Some(self.dimensions)
        } else if lines_is_non_zero || columns_is_non_zero {
            // Warn if either `columns` or `lines` is non-zero.

            let (zero_key, non_zero_key, non_zero_value) = if lines_is_non_zero {
                ("columns", "lines", lines)
            } else {
                ("lines", "columns", columns)
            };

            warn!(
                target: LOG_TARGET_CONFIG,
                "Both `lines` and `columns` must be non-zero for `window.dimensions` to take \
                 effect. Configured value of `{}` is 0 while that of `{}` is {}",
                zero_key,
                non_zero_key,
                non_zero_value,
            );

            None
        } else {
            None
        }
    }

    #[inline]
    pub fn padding(&self, scale_factor: f64) -> (f32, f32) {
        let padding_x = (f32::from(self.padding.x) * scale_factor as f32).floor();
        let padding_y = (f32::from(self.padding.y) * scale_factor as f32).floor();
        (padding_x, padding_y)
    }

    #[inline]
    pub fn fullscreen(&self) -> Option<Fullscreen> {
        if self.startup_mode == StartupMode::Fullscreen {
            Some(Fullscreen::Borderless(None))
        } else {
            None