@@ -360,9 +360,11 @@ func (r *Replica) sha512(
360
360
defer iter .Close ()
361
361
362
362
var alloc bufalloc.ByteAllocator
363
+ var intBuf [8 ]byte
364
+ var legacyTimestamp hlc.LegacyTimestamp
365
+ var timestampBuf []byte
363
366
hasher := sha512 .New ()
364
367
365
- var legacyTimestamp hlc.LegacyTimestamp
366
368
visitor := func (unsafeKey engine.MVCCKey , unsafeValue []byte ) error {
367
369
if snapshot != nil {
368
370
// Add (a copy of) the kv pair into the debug message.
@@ -375,24 +377,30 @@ func (r *Replica) sha512(
375
377
}
376
378
377
379
// Encode the length of the key and value.
378
- if err := binary .Write (hasher , binary .LittleEndian , int64 (len (unsafeKey .Key ))); err != nil {
380
+ binary .LittleEndian .PutUint64 (intBuf [:], uint64 (len (unsafeKey .Key )))
381
+ if _ , err := hasher .Write (intBuf [:]); err != nil {
379
382
return err
380
383
}
381
- if err := binary .Write (hasher , binary .LittleEndian , int64 (len (unsafeValue ))); err != nil {
384
+ binary .LittleEndian .PutUint64 (intBuf [:], uint64 (len (unsafeValue )))
385
+ if _ , err := hasher .Write (intBuf [:]); err != nil {
382
386
return err
383
387
}
384
388
if _ , err := hasher .Write (unsafeKey .Key ); err != nil {
385
389
return err
386
390
}
387
391
legacyTimestamp = hlc .LegacyTimestamp (unsafeKey .Timestamp )
388
- timestamp , err := protoutil .Marshal (& legacyTimestamp )
389
- if err != nil {
392
+ if size := legacyTimestamp .Size (); size > cap (timestampBuf ) {
393
+ timestampBuf = make ([]byte , size )
394
+ } else {
395
+ timestampBuf = timestampBuf [:size ]
396
+ }
397
+ if _ , err := protoutil .MarshalToWithoutFuzzing (& legacyTimestamp , timestampBuf ); err != nil {
390
398
return err
391
399
}
392
- if _ , err := hasher .Write (timestamp ); err != nil {
400
+ if _ , err := hasher .Write (timestampBuf ); err != nil {
393
401
return err
394
402
}
395
- _ , err = hasher .Write (unsafeValue )
403
+ _ , err : = hasher .Write (unsafeValue )
396
404
return err
397
405
}
398
406
0 commit comments