From df75794b3f3ae6f5533b229c3b593e44fabec3fa Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 6 Jun 2025 02:34:02 +0200 Subject: Try to be smarter about allocation? --- src/mintage/parser.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/mintage/parser.go') diff --git a/src/mintage/parser.go b/src/mintage/parser.go index 290f407..fe9ebd7 100644 --- a/src/mintage/parser.go +++ b/src/mintage/parser.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strconv" + "time" ) func Parse(country string) ([3]Data, error) { @@ -47,7 +48,7 @@ func Parse(country string) ([3]Data, error) { } func parseS(path string) ([]SRow, error) { - rows := make([]SRow, 0, 69) /* TODO: Compute number of rows */ + rows := make([]SRow, 0, guessRows(false)) f, err := os.Open(path) if err != nil { @@ -102,7 +103,7 @@ func parseS(path string) ([]SRow, error) { } func parseC(path string) ([]CRow, error) { - rows := make([]CRow, 0, 69) /* TODO: Compute number of rows */ + rows := make([]CRow, 0, guessRows(true)) f, err := os.Open(path) if err != nil { @@ -155,3 +156,13 @@ func parseC(path string) ([]CRow, error) { return rows, nil } + +func guessRows(commemorativep bool) int { + /* Try to guess the number of rows for Germany, because nobody needs more + rows than Germany. */ + n := (time.Now().Year() - 2002) * 5 + if commemorativep { + return n * 2 + } + return n +} -- cgit v1.2.3