Skip to content

Commit 99d0a34

Browse files
committed
optimize: replace make([]byte, 0) with nil
1 parent 1fc910a commit 99d0a34

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

client/auth/sig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func init() {
4444
}
4545

4646
func (sig *SigInfo) ClearSession() {
47-
sig.D2 = make([]byte, 0)
48-
sig.Tgt = make([]byte, 0)
47+
sig.D2 = nil
48+
sig.Tgt = nil
4949
sig.D2Key = make([]byte, 16)
5050
}
5151

client/packets/oidb/group_record_upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func BuildGroupRecordUploadReq(groupUin uint32, record *message.VoiceElement) (*
6464
TextSummary: record.Summary,
6565
},
6666
Video: &oidb.VideoExtBizInfo{
67-
BytesPbReserve: make([]byte, 0),
67+
BytesPbReserve: nil,
6868
},
6969
Ptt: &oidb.PttExtBizInfo{
70-
BytesReserve: make([]byte, 0),
70+
BytesReserve: nil,
7171
BytesPbReserve: []byte{0x08, 0x00, 0x38, 0x00},
7272
BytesGeneralFlags: []byte{0x9a, 0x01, 0x07, 0xaa, 0x03, 0x04, 0x08, 0x08, 0x12, 0x00},
7373
},

utils/binary/reader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (r *Reader) ReadBytesNoCopy(length int) (v []byte) {
145145
}
146146
// 确保缓冲区有足够的数据
147147
if r.pos+length > len(r.buffer) {
148-
return make([]byte, 0)
148+
return nil
149149
}
150150
v = r.buffer[r.pos : r.pos+length]
151151
r.pos += length
@@ -159,12 +159,12 @@ func (r *Reader) ReadBytes(length int) (v []byte) {
159159
n, err := io.ReadFull(r.reader, v)
160160
if err != nil || n < length {
161161
// 读取失败或读取的数据不足,返回空数组
162-
return make([]byte, 0)
162+
return nil
163163
}
164164
} else {
165165
// 确保缓冲区有足够的数据
166166
if r.pos+length > len(r.buffer) {
167-
return make([]byte, 0)
167+
return nil
168168
}
169169
copy(v, r.buffer[r.pos:r.pos+length])
170170
r.pos += length

0 commit comments

Comments
 (0)