day7: slight performance improvement from skipping ThreadLoacls
This commit is contained in:
		@@ -2,7 +2,6 @@ use aoc_runner_derive::{aoc, aoc_generator};
 | 
				
			|||||||
use itertools::Itertools;
 | 
					use itertools::Itertools;
 | 
				
			||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
 | 
					use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
 | 
				
			||||||
use std::io::{BufRead, Lines};
 | 
					use std::io::{BufRead, Lines};
 | 
				
			||||||
use thread_local::ThreadLocal;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[aoc_generator(day7)]
 | 
					#[aoc_generator(day7)]
 | 
				
			||||||
pub fn get_input(input: &[u8]) -> Calibrations {
 | 
					pub fn get_input(input: &[u8]) -> Calibrations {
 | 
				
			||||||
@@ -43,7 +42,7 @@ impl Operator {
 | 
				
			|||||||
        match self {
 | 
					        match self {
 | 
				
			||||||
            Operator::Add => a + b,
 | 
					            Operator::Add => a + b,
 | 
				
			||||||
            Operator::Multiply => a * b,
 | 
					            Operator::Multiply => a * b,
 | 
				
			||||||
            Operator::Concatenate => u64::pow(10, u64::ilog10(b) + 1) * a + b,
 | 
					            Operator::Concatenate => u64::pow(10, b.ilog10() + 1) * a + b,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -84,14 +83,12 @@ impl Calibrations {
 | 
				
			|||||||
            .par_iter()
 | 
					            .par_iter()
 | 
				
			||||||
            .map(|cal| {
 | 
					            .map(|cal| {
 | 
				
			||||||
                let n_opers = cal.numbers.len() - 1;
 | 
					                let n_opers = cal.numbers.len() - 1;
 | 
				
			||||||
                let tl = ThreadLocal::new();
 | 
					 | 
				
			||||||
                if operator_sets[n_opers]
 | 
					                if operator_sets[n_opers]
 | 
				
			||||||
                    .par_iter()
 | 
					                    .par_iter()
 | 
				
			||||||
                    .find_any(|oper_set| Self::check_oper_set(cal, oper_set))
 | 
					                    .find_any(|oper_set| Self::check_oper_set(cal, oper_set))
 | 
				
			||||||
                    .is_some()
 | 
					                    .is_some()
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    let cal_local = tl.get_or(|| cal.clone());
 | 
					                    return cal.result;
 | 
				
			||||||
                    return cal_local.result;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                0
 | 
					                0
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user