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

View file

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