@@ -30,8 +30,31 @@ func NewSet() *SignatureBatch {
30
30
}
31
31
}
32
32
33
- // Join merges the provided signature batch to out current one.
34
33
func (s * SignatureBatch ) Join (set * SignatureBatch ) * SignatureBatch {
34
+ total := len (s .Signatures ) + len (set .Signatures )
35
+
36
+ // Preallocate capacity if needed
37
+ if cap (s .Signatures ) < total {
38
+ newSigs := make ([][]byte , len (s .Signatures ), total )
39
+ copy (newSigs , s .Signatures )
40
+ s .Signatures = newSigs
41
+ }
42
+ if cap (s .PublicKeys ) < total {
43
+ newPKs := make ([]PublicKey , len (s .PublicKeys ), total )
44
+ copy (newPKs , s .PublicKeys )
45
+ s .PublicKeys = newPKs
46
+ }
47
+ if cap (s .Messages ) < total {
48
+ newMsgs := make ([][32 ]byte , len (s .Messages ), total )
49
+ copy (newMsgs , s .Messages )
50
+ s .Messages = newMsgs
51
+ }
52
+ if cap (s .Descriptions ) < total {
53
+ newDescs := make ([]string , len (s .Descriptions ), total )
54
+ copy (newDescs , s .Descriptions )
55
+ s .Descriptions = newDescs
56
+ }
57
+
35
58
s .Signatures = append (s .Signatures , set .Signatures ... )
36
59
s .PublicKeys = append (s .PublicKeys , set .PublicKeys ... )
37
60
s .Messages = append (s .Messages , set .Messages ... )
0 commit comments