diff --git a/.golangci.yml b/.golangci.yml index 8b30f15..7142304 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -64,6 +64,7 @@ linters: - "ineffassign" - "interfacebloat" # - "interfacer" # Archived. + - intrange # - "ireturn" # Too many false positive. # - "lll" # We don't use punch cards anymore. - "loggercheck" diff --git a/geohash.go b/geohash.go index 244a5be..018027f 100644 --- a/geohash.go +++ b/geohash.go @@ -25,7 +25,7 @@ func init() { for i := range base32Lookup { base32Lookup[i] = -1 } - for i := 0; i < len(base32); i++ { + for i := range len(base32) { base32Lookup[base32[i]] = i } } @@ -56,7 +56,7 @@ func Encode(lat, lon float64, precision int) string { var buf [encodeMaxPrecision]byte box := defaultBox even := true - for i := 0; i < precision; i++ { + for i := range precision { ci := 0 for mask := 1 << 4; mask != 0; mask >>= 1 { var r *Range @@ -85,7 +85,7 @@ func Encode(lat, lon float64, precision int) string { func Decode(gh string) (Box, error) { box := defaultBox even := true - for i := 0; i < len(gh); i++ { + for i := range len(gh) { ci := base32Lookup[gh[i]] if ci == -1 { return box, fmt.Errorf("geohash decode '%s': invalid character at index %d", gh, i) diff --git a/geohash_benchmark_test.go b/geohash_benchmark_test.go index 19c4d59..4428d6e 100644 --- a/geohash_benchmark_test.go +++ b/geohash_benchmark_test.go @@ -13,13 +13,13 @@ import ( ) func BenchmarkEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { Encode(testPoint.Lat, testPoint.Lon, testPrecision) } } func BenchmarkDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { _, err := Decode(testGeohash) if err != nil { assert.NoError(b, err) @@ -28,7 +28,7 @@ func BenchmarkDecode(b *testing.B) { } func BenchmarkNeighbors(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { _, err := GetNeighbors(testGeohash) if err != nil { assert.NoError(b, err) @@ -37,79 +37,79 @@ func BenchmarkNeighbors(b *testing.B) { } func BenchmarkCodeforEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { codefor_geohash.Encode(testPoint.Lat, testPoint.Lon) } } func BenchmarkCodeforDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { codefor_geohash.Decode(testGeohash) } } func BenchmarkTomiHiltunenEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { tomi_hiltunen_geohash.EncodeWithPrecision(testPoint.Lat, testPoint.Lon, testPrecision) } } func BenchmarkTomiHiltunenDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { tomi_hiltunen_geohash.Decode(testGeohash) } } func BenchmarkTomiHiltunenNeighbors(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { tomi_hiltunen_geohash.CalculateAllAdjacent(testGeohash) } } func BenchmarkBroadyEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { broadygeohash.Encode(testPoint.Lat, testPoint.Lon) } } func BenchmarkBroadyDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { broadygeohash.Decode(testGeohash) } } func BenchmarkFanixkEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { fanixk_geohash.PrecisionEncode(testPoint.Lat, testPoint.Lon, testPrecision) } } func BenchmarkFanixkDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { fanixk_geohash.DecodeBoundingBox(testGeohash) } } func BenchmarkFanixkNeighbors(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { fanixk_geohash.Neighbors(testGeohash) } } func BenchmarkMmcloughlinEncode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { mmcloughlin_geohash.EncodeWithPrecision(testPoint.Lat, testPoint.Lon, testPrecision) } } func BenchmarkMmcloughlinDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { mmcloughlin_geohash.BoundingBox(testGeohash) } } func BenchmarkMmcloughlinNeighbors(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { fanixk_geohash.Neighbors(testGeohash) } } @@ -122,13 +122,13 @@ func BenchmarkThe42CartconvertEncode(b *testing.B) { El: the42_cartconvert_geohash.DefaultEllipsoid, } precision := byte(testPrecision) - for i := 0; i < b.N; i++ { + for range b.N { the42_cartconvert_geohash.LatLongToGeoHashBits(pc, precision) } } func BenchmarkThe42CartconvertDecode(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { _, err := the42_cartconvert_geohash.GeoHashToLatLong(testGeohash, the42_cartconvert_geohash.DefaultEllipsoid) if err != nil { assert.NoError(b, err)