BufPool for Identifier

This commit is contained in:
Patrick O'brien 2016-08-13 23:30:53 +10:00
parent d2862ef281
commit e4800f9af8
2 changed files with 5 additions and 4 deletions

View file

@ -78,17 +78,18 @@ func Identifier(in int) string {
n = 1 + int(math.Log(float64(in))/math.Log(float64(ln))) n = 1 + int(math.Log(float64(in))/math.Log(float64(ln)))
} }
cols := make([]byte, n) cols := GetBuffer()
defer PutBuffer(cols)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
divisor := int(math.Pow(float64(ln), float64(n-i-1))) divisor := int(math.Pow(float64(ln), float64(n-i-1)))
rem := in / divisor rem := in / divisor
cols[i] = idAlphabet[rem] cols.WriteByte(idAlphabet[rem])
in -= rem * divisor in -= rem * divisor
} }
return string(cols) return cols.String()
} }
// Plural converts singular words to plural words (eg: person to people) // Plural converts singular words to plural words (eg: person to people)

View file

@ -47,7 +47,7 @@ func TestIdentQuoteSlice(t *testing.T) {
} }
} }
func TestIDGen(t *testing.T) { func TestIdentifier(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []struct {