etcdserver: preallocate slice in apply
@@ -224,8 +224,9 @@ func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequ
return nil, err
}
if rr != nil {
+ resp.PrevKvs = make([]*mvccpb.KeyValue, len(rr.KVs))
for i := range rr.KVs {
- resp.PrevKvs = append(resp.PrevKvs, &rr.KVs[i])
+ resp.PrevKvs[i] = &rr.KVs[i]
}
}
}
@@ -319,11 +320,12 @@ func (a *applierV3backend) Range(txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.Rang
resp.Header.Revision = rr.Rev
resp.Count = int64(rr.Count)
+ resp.Kvs = make([]*mvccpb.KeyValue, len(rr.KVs))
for i := range rr.KVs {
if r.KeysOnly {
rr.KVs[i].Value = nil
}
- resp.Kvs = append(resp.Kvs, &rr.KVs[i])
+ resp.Kvs[i] = &rr.KVs[i]
}
return resp, nil
}
