File tree Expand file tree Collapse file tree 2 files changed +17
-24
lines changed Expand file tree Collapse file tree 2 files changed +17
-24
lines changed Original file line number Diff line number Diff line change 1
1
package rpmdb
2
2
3
3
import (
4
- "bytes"
5
4
"encoding/binary"
6
- "log"
7
5
)
8
6
9
7
func Htonl (val int32 ) int32 {
10
- buf := new (bytes.Buffer )
11
- if err := binary .Write (buf , binary .LittleEndian , val ); err != nil {
12
- log .Println (err )
13
- return 0
14
- }
15
-
16
- if err := binary .Read (buf , binary .BigEndian , & val ); err != nil {
17
- log .Println (err )
18
- return 0
19
- }
20
- return val
8
+ var buf [4 ]byte
9
+ binary .LittleEndian .PutUint32 (buf [:], uint32 (val ))
10
+ return int32 (binary .BigEndian .Uint32 (buf [:]))
21
11
}
22
12
23
13
func HtonlU (val uint32 ) uint32 {
24
- buf := new (bytes.Buffer )
25
- if err := binary .Write (buf , binary .LittleEndian , val ); err != nil {
26
- log .Println (err )
27
- return 0
28
- }
29
-
30
- if err := binary .Read (buf , binary .BigEndian , & val ); err != nil {
31
- log .Println (err )
32
- return 0
33
- }
34
- return val
14
+ var buf [4 ]byte
15
+ binary .LittleEndian .PutUint32 (buf [:], val )
16
+ return binary .BigEndian .Uint32 (buf [:])
35
17
}
Original file line number Diff line number Diff line change @@ -119,6 +119,17 @@ func TestPackageList(t *testing.T) {
119
119
}
120
120
})
121
121
}
122
+
123
+ for _ , tt := range tests {
124
+ allocs := testing .AllocsPerRun (10 , func () {
125
+ db , err := Open (tt .file )
126
+ require .NoError (t , err )
127
+
128
+ _ , err = db .ListPackages ()
129
+ require .NoError (t , err )
130
+ })
131
+ t .Logf ("Allocations per run %q: %f" , tt .name , allocs )
132
+ }
122
133
}
123
134
124
135
func TestRpmDB_Package (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments