improve slice copying

This commit is contained in:
c9s 2021-01-25 14:20:56 +08:00
parent b99c01a03f
commit ca71c81284

View File

@ -38,8 +38,9 @@ func (slice PriceVolumeSlice) Trim() (pvs PriceVolumeSlice) {
} }
func (slice PriceVolumeSlice) Copy() PriceVolumeSlice { func (slice PriceVolumeSlice) Copy() PriceVolumeSlice {
// this is faster than make (however it's only for simple types) var s = make(PriceVolumeSlice, len(slice), len(slice))
return append(slice[:0:0], slice...) copy(s, slice)
return s
} }
func (slice PriceVolumeSlice) First() (PriceVolume, bool) { func (slice PriceVolumeSlice) First() (PriceVolume, bool) {