From bb89a865d42dd1b460cfb6cb26006dea2aac96b1 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 24 May 2020 07:03:19 -0400 Subject: [PATCH] remove clones when paring hsla colors --- src/color/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/color/mod.rs b/src/color/mod.rs index 7014159..7dd8f15 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -15,6 +15,7 @@ //! Named colors retain their original casing, //! so `rEd` should be emitted as `rEd`. +use std::cmp::{max, min}; use std::fmt::{self, Display}; use crate::value::Number; @@ -198,8 +199,8 @@ impl Color { let red = self.red() / Number::from(255); let green = self.green() / Number::from(255); let blue = self.blue() / Number::from(255); - let min = red.clone().min(green.clone().min(blue.clone())); - let max = red.clone().max(green.clone().max(blue.clone())); + let min = min(&red, min(&green, &blue)).clone(); + let max = max(&red, max(&green, &blue)).clone(); if min == max { return Number::zero(); } @@ -229,7 +230,7 @@ impl Color { let green = self.green() / Number::from(255); let blue = self.blue() / Number::from(255); - let min = red.clone().min(green.clone().min(blue.clone())); + let min = min(&red, min(&green, &blue)).clone(); let max = red.max(green.max(blue)); if min == max { @@ -255,7 +256,7 @@ impl Color { let red = self.red() / Number::from(255); let green = self.green() / Number::from(255); let blue = self.blue() / Number::from(255); - let min = red.clone().min(green.clone().min(blue.clone())); + let min = min(&red, min(&green, &blue)).clone(); let max = red.max(green.max(blue)); (((min + max) / Number::from(2)) * Number::from(100)).round() } @@ -268,8 +269,8 @@ impl Color { let red = self.red() / Number::from(255); let green = self.green() / Number::from(255); let blue = self.blue() / Number::from(255); - let min = red.clone().min(green.clone().min(blue.clone())); - let max = red.clone().max(green.clone().max(blue.clone())); + let min = min(&red, min(&green, &blue)).clone(); + let max = max(&red, max(&green, &blue)).clone(); let lightness = (min.clone() + max.clone()) / Number::from(2);