Skip to content

Commit 63224b4

Browse files
committed
go1.24
1 parent a60e286 commit 63224b4

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: go
1717
uses: actions/setup-go@v5
1818
with:
19-
go-version: ^1.23
19+
go-version: ^1.24
2020

2121
- name: test
2222
run: |

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/ndx-technologies/base10quant
22

3-
go 1.23.0
3+
go 1.24.0

l9.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ func (s L9) UInt32() uint32 { return s.v }
2626

2727
func (s L9) IsEmpty() bool { return s.v == 0 }
2828

29-
func (s L9) AppendBytes(b []byte) {
29+
func (s L9) AppendText(b []byte) ([]byte, error) {
30+
n := len(b)
31+
b = append(b, make([]byte, 9)...)
32+
3033
v := s.v
31-
v, b[8] = v/10, '0'+byte(v%10)
32-
v, b[7] = v/10, '0'+byte(v%10)
33-
v, b[6] = v/10, '0'+byte(v%10)
34-
v, b[5] = v/10, '0'+byte(v%10)
35-
v, b[4] = v/10, '0'+byte(v%10)
36-
v, b[3] = v/10, '0'+byte(v%10)
37-
v, b[2] = v/10, '0'+byte(v%10)
38-
v, b[1] = v/10, '0'+byte(v%10)
39-
_, b[0] = v/10, '0'+byte(v%10)
34+
v, b[n+8] = v/10, '0'+byte(v%10)
35+
v, b[n+7] = v/10, '0'+byte(v%10)
36+
v, b[n+6] = v/10, '0'+byte(v%10)
37+
v, b[n+5] = v/10, '0'+byte(v%10)
38+
v, b[n+4] = v/10, '0'+byte(v%10)
39+
v, b[n+3] = v/10, '0'+byte(v%10)
40+
v, b[n+2] = v/10, '0'+byte(v%10)
41+
v, b[n+1] = v/10, '0'+byte(v%10)
42+
_, b[n+0] = v/10, '0'+byte(v%10)
43+
return b, nil
4044
}
4145

4246
func (s L9) MarshalText() ([]byte, error) {
43-
b := make([]byte, 9)
44-
s.AppendBytes(b)
45-
return b, nil
47+
b := make([]byte, 0, 9)
48+
return s.AppendText(b)
4649
}
4750

4851
func (s *L9) UnmarshalText(b []byte) error {

l9_test.go

+4-22
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,19 @@ func BenchmarkL9(b *testing.B) {
103103
b.Run("string", func(b *testing.B) {
104104
x := rand.Uint32()
105105
v := base10quant.L9FromUint32(x)
106-
var s string
107106

108-
b.ResetTimer()
109-
for i := 0; i < b.N; i++ {
110-
s = v.String()
111-
}
112-
113-
if len(s) == 0 {
114-
b.Fatal("unexpected empty string")
107+
for b.Loop() {
108+
v.String()
115109
}
116110
})
117111

118112
b.Run("from_string", func(b *testing.B) {
119113
x := rand.Uint32()
120114
v := base10quant.L9FromUint32(x)
121115
s := v.String()
122-
var err error
123-
124-
b.ResetTimer()
125-
for i := 0; i < b.N; i++ {
126-
v, err = base10quant.L9FromString(s)
127-
}
128116

129-
if len(s) == 0 {
130-
b.Fatal("unexpected empty string")
131-
}
132-
if v == (base10quant.L9{}) {
133-
b.Fatal("unexpected empty value")
134-
}
135-
if err != nil {
136-
b.Fatal(err)
117+
for b.Loop() {
118+
base10quant.L9FromString(s)
137119
}
138120
})
139121
}

0 commit comments

Comments
 (0)