Skip to content

Commit c0cefb0

Browse files
illia-lijameshartig
authored andcommitted
<framer> optimization writeHeader(...) method
Fixes: * splits all `append` operations in one Patch by illia-li; reviewed by ... for CASSGO-...
1 parent 5f4d36a commit c0cefb0

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

frame.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -700,31 +700,19 @@ func (f *framer) readErrorMap() (errMap ErrorMap) {
700700
}
701701

702702
func (f *framer) writeHeader(flags byte, op frameOp, stream int) {
703-
f.buf = f.buf[:0]
704-
f.buf = append(f.buf,
705-
f.proto,
706-
flags,
707-
)
708-
709-
if f.proto > protoVersion2 {
710-
f.buf = append(f.buf,
711-
byte(stream>>8),
712-
byte(stream),
703+
if f.proto <= protoVersion2 {
704+
f.buf = append(f.buf[:0],
705+
f.proto, flags, byte(stream),
706+
// pad out length
707+
byte(op), 0, 0, 0, 0,
713708
)
714709
} else {
715-
f.buf = append(f.buf,
716-
byte(stream),
710+
f.buf = append(f.buf[:0],
711+
f.proto, flags, byte(stream>>8), byte(stream),
712+
// pad out length
713+
byte(op), 0, 0, 0, 0,
717714
)
718715
}
719-
720-
// pad out length
721-
f.buf = append(f.buf,
722-
byte(op),
723-
0,
724-
0,
725-
0,
726-
0,
727-
)
728716
}
729717

730718
func (f *framer) setLength(length int) {

0 commit comments

Comments
 (0)