Minor optimizations
This commit is contained in:
		
							
								
								
									
										42
									
								
								src/util.rs
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								src/util.rs
									
									
									
									
									
								
							@ -69,17 +69,39 @@ impl Symb {
 | 
			
		||||
		self == &Self::Minus
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pub fn from_char(c: char) -> Option<Self> {
 | 
			
		||||
	pub const fn to_char(&self) -> Option<char> {
 | 
			
		||||
		match self {
 | 
			
		||||
			Self::Plus => Some('+'),
 | 
			
		||||
			Self::Minus => Some('-'),
 | 
			
		||||
			Self::Times => Some('×'),
 | 
			
		||||
			Self::Div => Some('÷'),
 | 
			
		||||
			Self::Zero => Some('0'),
 | 
			
		||||
			Self::Number(x) => match x.get() {
 | 
			
		||||
				1 => Some('1'),
 | 
			
		||||
				2 => Some('2'),
 | 
			
		||||
				3 => Some('3'),
 | 
			
		||||
				4 => Some('4'),
 | 
			
		||||
				5 => Some('5'),
 | 
			
		||||
				6 => Some('6'),
 | 
			
		||||
				7 => Some('7'),
 | 
			
		||||
				8 => Some('8'),
 | 
			
		||||
				9 => Some('9'),
 | 
			
		||||
				_ => None,
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pub const fn from_char(c: char) -> Option<Self> {
 | 
			
		||||
		match c {
 | 
			
		||||
			'1' => Some(Self::Number(NonZeroU8::new(1).unwrap())),
 | 
			
		||||
			'2' => Some(Self::Number(NonZeroU8::new(2).unwrap())),
 | 
			
		||||
			'3' => Some(Self::Number(NonZeroU8::new(3).unwrap())),
 | 
			
		||||
			'4' => Some(Self::Number(NonZeroU8::new(4).unwrap())),
 | 
			
		||||
			'5' => Some(Self::Number(NonZeroU8::new(5).unwrap())),
 | 
			
		||||
			'6' => Some(Self::Number(NonZeroU8::new(6).unwrap())),
 | 
			
		||||
			'7' => Some(Self::Number(NonZeroU8::new(7).unwrap())),
 | 
			
		||||
			'8' => Some(Self::Number(NonZeroU8::new(8).unwrap())),
 | 
			
		||||
			'9' => Some(Self::Number(NonZeroU8::new(9).unwrap())),
 | 
			
		||||
			'1' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(1) })),
 | 
			
		||||
			'2' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(2) })),
 | 
			
		||||
			'3' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(3) })),
 | 
			
		||||
			'4' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(4) })),
 | 
			
		||||
			'5' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(5) })),
 | 
			
		||||
			'6' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(6) })),
 | 
			
		||||
			'7' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(7) })),
 | 
			
		||||
			'8' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(8) })),
 | 
			
		||||
			'9' => Some(Self::Number(unsafe { NonZeroU8::new_unchecked(9) })),
 | 
			
		||||
			'0' => Some(Self::Zero),
 | 
			
		||||
			'+' => Some(Self::Plus),
 | 
			
		||||
			'-' => Some(Self::Minus),
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user