1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-14 07:50:08 +01:00

Improve Performance

Dieser Commit ist enthalten in:
Chaoscaot 2023-08-20 15:37:23 +02:00
Ursprung e3e6e9f759
Commit d20940f89b
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
2 geänderte Dateien mit 16 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -39,30 +39,30 @@ pub fn search(
search_behavior: SearchBehavior,
) -> Vec<Match> {
if schem.width < pattern_schem.width || schem.height < pattern_schem.height || schem.length < pattern_schem.length {
return vec![];
return Vec::new();
}
if pattern_schem.palette.len() > schem.palette.len() {
return vec![];
return Vec::new();
}
let pattern_schem = match_palette(&schem, &pattern_schem, search_behavior.ignore_block_data);
let mut matches: Vec<Match> = Vec::new();
let mut matches: Vec<Match> = Vec::with_capacity(4);
let pattern_data = pattern_schem.block_data.as_slice();
let pattern_data = pattern_schem.block_data.as_ptr();
let schem_data = if search_behavior.ignore_block_data {
match_palette_adapt(&schem, &pattern_schem.palette, search_behavior.ignore_block_data)
} else {
schem.block_data.clone()
schem.block_data
};
let schem_data = schem_data.as_slice();
let schem_data = schem_data.as_ptr();
let air_id = if search_behavior.ignore_air || search_behavior.air_as_any { pattern_schem.palette.get("minecraft:air").unwrap_or(&-1) } else { &-1};
let pattern_blocks = pattern_data.len() as f32;
let pattern_blocks = pattern_schem.block_data.len() as f32;
let i_pattern_blocks = pattern_blocks as i32;
let pattern_width = pattern_schem.width as usize;
@ -86,16 +86,16 @@ pub fn search(
for i in 0..pattern_width {
let index = (x + i) + schem_width * ((z + k) + (y + j) * schem_length);
let pattern_index = i + pattern_width * (k + j * pattern_length);
let data = unsafe {schem_data.get_unchecked(index) };
let pattern_data = unsafe { pattern_data.get_unchecked(pattern_index) };
if (search_behavior.ignore_air && *data != *air_id) || (search_behavior.air_as_any && *pattern_data != *air_id) {
let data = unsafe { *schem_data.add(index) };
let pattern_data = unsafe { *pattern_data.add(pattern_index) };
if (search_behavior.ignore_air && data != *air_id) || (search_behavior.air_as_any && pattern_data != *air_id) {
continue 'inner;
}
if *data != *pattern_data {
if data != pattern_data {
not_matching += 1;
}
if not_matching >= skip_amount {
break 'outer;
if not_matching >= skip_amount {
break 'outer;
}
}
}
}
@ -109,7 +109,6 @@ pub fn search(
percent: (i_pattern_blocks - not_matching) as f32 / pattern_blocks,
});
}
}
}
}

Datei anzeigen

@ -64,10 +64,10 @@ pub fn strip_data(schem: &SpongeSchematic) -> SpongeSchematic {
}
pub fn match_palette_adapt(schem: &SpongeSchematic, matching_palette: &HashMap<String, i32>, ignore_data: bool) -> Vec<i32> {
let mut data: Vec<i32> = Vec::new();
let mut data = Vec::with_capacity(schem.block_data.len());
let reverse_palette = create_reverse_palette(schem);
for x in schem.block_data.iter() {
for x in schem.block_data.as_slice().iter() {
let blockname = reverse_palette[*x as usize];
let blockname = if ignore_data { normalize_data(blockname, ignore_data) } else { blockname };
let block_id = match matching_palette.get(&*blockname) {