summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-10 13:13:08 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-10 13:13:08 +0200
commitc1b13e2d3700222adf8e440cb1fa1673a9904170 (patch)
treec3ffcfa1c133382fc9b75af202d124a66f21959b /cmd
parent6485051871302b42672b8363b2d0d0af541eb675 (diff)
Refactor strconv.Iota() out
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mfmt/main.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/cmd/mfmt/main.go b/cmd/mfmt/main.go
index 2f204ab..5c189ea 100644
--- a/cmd/mfmt/main.go
+++ b/cmd/mfmt/main.go
@@ -5,7 +5,6 @@ import (
"io"
"os"
"path/filepath"
- "strconv"
"strings"
"unsafe"
@@ -94,7 +93,8 @@ func formatSection(out io.Writer, rows []mintages.Row) {
}
year = s
for i, col := range row.Cols {
- longestNum[i] = max(longestNum[i], intlen(col))
+ n := intlen(col)
+ longestNum[i] = max(longestNum[i], n+(n-1)/3)
}
}
@@ -139,18 +139,19 @@ func formatInt(n int) string {
return "?"
}
- in := strconv.Itoa(n)
- dots := (len(in) - 1) / 3
- out := make([]byte, len(in)+dots)
+ digits := intlen(n)
+ dots := (digits - 1) / 3
+ out := make([]byte, digits+dots)
- for i, j, k := len(in)-1, len(out)-1, 0; ; i, j = i-1, j-1 {
- out[j] = in[i]
- if i == 0 {
+ for i, j := len(out)-1, 0; ; i-- {
+ out[i] = byte(n%10) + 48
+ n /= 10
+ if n == 0 {
return string(out)
}
- if k++; k == 3 {
- j, k = j-1, 0
- out[j] = '.'
+ if j++; j == 3 {
+ i, j = i-1, 0
+ out[i] = '.'
}
}
}
@@ -166,7 +167,7 @@ func intlen(v int) int {
for x := v; x != 0; x /= 10 {
n++
}
- return n + (n-1)/3 /* Thousands separators */
+ return n
}
}