Skip to content

Commit cec7835

Browse files
committed
Merge branch 'perf-2' into perf-3
2 parents 54bdf28 + 19d202a commit cec7835

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

go/decode.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func Decode(code string) (CodeArea, error) {
2626
}
2727
// Strip out separator character, padding characters and convert to upper
2828
// case.
29-
codeBytes := StripCode(code)
30-
codeLen := len(codeBytes)
29+
code = StripCode(code)
30+
codeLen := len(code)
3131
// lat and lng build up the integer values.
3232
var lat int64
3333
var lng int64
@@ -42,8 +42,8 @@ func Decode(code string) (CodeArea, error) {
4242
lng *= encBase
4343
height *= encBase
4444
if i < codeLen {
45-
lat += alphabetPosition[codeBytes[i]]
46-
lng += alphabetPosition[codeBytes[i+1]]
45+
lat += alphabetPosition[code[i]]
46+
lng += alphabetPosition[code[i+1]]
4747
height = 1
4848
}
4949
}
@@ -56,7 +56,7 @@ func Decode(code string) (CodeArea, error) {
5656
lng *= gridCols
5757
width *= gridCols
5858
if i < codeLen {
59-
dval := alphabetPosition[codeBytes[i]]
59+
dval := alphabetPosition[code[i]]
6060
lat += dval / gridCols
6161
lng += dval % gridCols
6262
height = 1

go/olc.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ func CheckFull(code string) error {
189189
return nil
190190
}
191191

192+
func upper(b byte) byte {
193+
if 'c' <= b && b <= 'x' {
194+
return b + 'C' - 'c'
195+
}
196+
return b
197+
}
198+
192199
// StripCode strips the padding and separator characters from the code.
193200
//
194201
// The code is truncated to the first 15 digits, as Decode won't use more,
@@ -200,7 +207,7 @@ func StripCode(code string) string {
200207
if r == Separator || r == Padding {
201208
continue
202209
}
203-
result[pos] = byte(r)
210+
result[pos] = upper(byte(r))
204211
pos++
205212
if pos >= maxCodeLen {
206213
break

0 commit comments

Comments
 (0)