Skip to content

Commit cb311ed

Browse files
aykevldeadprogram
authored andcommitted
machine: optimize RTT initialization
This converts the heap allocation to a statically allocated string. This is useful for me, since it reduces binary size and makes it possible to use `-gc=none` (which would previously result in a linker error).
1 parent 6f686d1 commit cb311ed

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/machine/serial-rtt.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,18 @@ type rttSerial struct {
7171
rttControlBlock
7272
}
7373

74+
var terminalByteString = []byte("Terminal\x00")
75+
7476
func (s *rttSerial) Configure(config UARTConfig) error {
7577
s.maxNumUpBuffers = rttMaxNumUpBuffers
7678
s.maxNumDownBuffers = rttMaxNumDownBuffers
7779

78-
s.buffersUp[0].name = &[]byte("Terminal\x00")[0]
80+
s.buffersUp[0].name = &terminalByteString[0]
7981
s.buffersUp[0].buffer = &rttBufferUpData[0]
8082
s.buffersUp[0].bufferSize = rttBufferSizeUp
8183
s.buffersUp[0].flags = rttModeNoBlockSkip
8284

83-
s.buffersDown[0].name = &[]byte("Terminal\x00")[0]
85+
s.buffersDown[0].name = &terminalByteString[0]
8486
s.buffersDown[0].buffer = &rttBufferDownData[0]
8587
s.buffersDown[0].bufferSize = rttBufferSizeDown
8688
s.buffersDown[0].flags = rttModeNoBlockSkip

0 commit comments

Comments
 (0)