-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimizations: Only link used datasets, avoid copies, avoid pkg/error…
…s dependency (#26) * Run go fmt * Ignore GoLand IDE directory * Let linker strip unused datasets This is achieved by making each dataset a separatge variable, which can be stripped out by the linker when it is no referenced anywhere. Also avoids unnecessary copies of gzipped dataset. * Remove github.com/pkg/errors dependency * Update dependencies * Use Go 1.21 in CI Go version in go.mod can remain at 1.19 for compatibility. * Preallocate slices
- Loading branch information
Showing
7 changed files
with
62 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
package rgeo | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"io" | ||
) | ||
// embedding files individually here to allow the linker to strip out unused ones | ||
import _ "embed" | ||
|
||
//go:embed data/* | ||
var dataDir embed.FS | ||
//go:embed data/Cities10.gz | ||
var cities10 []byte | ||
|
||
func Cities10() []byte { | ||
return readEmbedFile("Cities10.gz") | ||
return cities10 | ||
} | ||
|
||
//go:embed data/Countries10.gz | ||
var countries10 []byte | ||
|
||
func Countries10() []byte { | ||
return readEmbedFile("Countries10.gz") | ||
return countries10 | ||
} | ||
|
||
func Countries110() []byte { | ||
return readEmbedFile("Countries110.gz") | ||
} | ||
//go:embed data/Countries110.gz | ||
var countries110 []byte | ||
|
||
func Provinces10() []byte { | ||
return readEmbedFile("Provinces10.gz") | ||
func Countries110() []byte { | ||
return countries110 | ||
} | ||
|
||
func readEmbedFile(name string) []byte { | ||
f, err := dataDir.Open(fmt.Sprintf("data/%s", name)) | ||
if err != nil { | ||
panic(fmt.Sprintf("internal embedded geojson open error %v", err)) | ||
} | ||
//go:embed data/Provinces10.gz | ||
var provinces10 []byte | ||
|
||
b, _ := io.ReadAll(f) | ||
return b | ||
func Provinces10() []byte { | ||
return provinces10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= | ||
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= | ||
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 h1:enTowfyfjtomBQhxX9mhUD+0tZhpe4rIzStO4aNlou8= | ||
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= | ||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 h1:HKlyj6in2JV6wVkmQ4XmG/EIm+SCYlPZ+V4GWit7Z+I= | ||
github.com/golang/geo v0.0.0-20230421003525-6adc56603217/go.mod h1:8wI0hitZ3a1IxZfeH3/5I97CI8i5cLGsYe7xNhQGs9U= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
github.com/twpayne/go-geom v1.4.4 h1:bcCPAvvNSzjmpUqR0Uqh39ClCKtPx6kZVR7EakQaVJI= | ||
github.com/twpayne/go-geom v1.4.4/go.mod h1:Kz4sX4LtdesDQgkhsMERazLlH/NiCg90s6FPaNr0KNI= | ||
github.com/twpayne/go-geom v1.5.2 h1:LyRfBX2W0LM7XN/bGqX0XxrJ7SZc3XwmxU4aj4kSoxw= | ||
github.com/twpayne/go-geom v1.5.2/go.mod h1:3z6O2sAnGtGCXx4Q+5nPOLCA5e8WI2t3cthdb1P2HH8= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters