A couple optimizations to file load speeds

This commit is contained in:
Emi Simpson 2023-02-12 16:58:59 -05:00
parent c71ea2616e
commit 66bd8bbec8
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 6 additions and 5 deletions

View File

@ -36,10 +36,11 @@ def read_single_elevation(dat: str) -> Result[int, str]:
>>> read_single_elevation("10.0m")
Err('10.0m')
"""
return map_res(
meters_to_millimeters, # fuck floating points
try_(replace(dat), float, dat)
)
try:
# fuck floating points
return Ok(meters_to_millimeters(float(dat)))
except ValueError:
return Err(dat)
def read_elevation_line(line: str) -> Result[Sequence[int], Tuple[int, str]]:
"""
@ -186,7 +187,7 @@ def load_gb_pixels_as_map(pixels: Iterable[Tuple[int, int]]) -> Result[Sequence[
"""
return sequence([
note(
UnrecognizedColor(pix_no % 395, pix_no // 395),
lambda: UnrecognizedColor(pix_no % 395, pix_no // 395),
gb_to_terrain_type(gb)
)
for (pix_no, gb) in enumerate(pixels)