An even faster lookup is creating a [256]byte array for the replacements,
having the 9 replacements candidates _position_ having the replacements,
all others the identity:
// prepare the lookup table
var a [256]byte
for i := 0; i<256; i++ {
a[i] = i
}
a[37] = '-'
a[129] = '-'
...
// replace the bytes, in-place operation
func replace(p []byte) {
for i, b := range p {
p[i] = a[b]
}
}
Although map lookup is O(1), array lookup is O(1) with a smaller constant
factor, I'm sure.
And this has no branching, so should be even faster.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.