File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package goapai
22
33import (
44 "encoding/binary"
5- "fmt"
65 "hash/fnv"
76 "slices"
87 "strconv"
@@ -98,19 +97,25 @@ func (statesData statesData) sort() {
9897func (statesData statesData ) hashStates () uint64 {
9998 hash := fnv .New64 ()
10099
100+ buf := make ([]byte , binary .MaxVarintLen64 )
101101 for _ , data := range statesData {
102- hash .Write ([]byte (strconv .Itoa (int (data .GetKey ()))))
102+ n := binary .PutVarint (buf , int64 (data .GetKey ()))
103+ hash .Write (buf [:n ])
103104 hash .Write ([]byte (":" ))
104105
105106 switch v := data .GetValue ().(type ) {
106107 case int8 :
107- hash .Write ([]byte (fmt .Sprintf ("%v" , v )))
108+ n = binary .PutVarint (buf , int64 (v ))
109+ hash .Write (buf [:n ])
108110 case int :
109- hash .Write ([]byte (strconv .Itoa (v )))
111+ n = binary .PutVarint (buf , int64 (v ))
112+ hash .Write (buf [:n ])
110113 case uint8 :
111- hash .Write ([]byte (fmt .Sprintf ("%v" , v )))
114+ n = binary .PutUvarint (buf , uint64 (v ))
115+ hash .Write (buf [:n ])
112116 case uint64 :
113- hash .Write ([]byte (fmt .Sprintf ("%v" , v )))
117+ n = binary .PutUvarint (buf , v )
118+ hash .Write (buf [:n ])
114119 case float64 :
115120 hash .Write ([]byte (strconv .FormatFloat (v , 'f' , - 1 , 64 )))
116121 case string :
You can’t perform that action at this time.
0 commit comments