Skip to content

Commit 4164c39

Browse files
aykevldeadprogram
authored andcommitted
machine/nrf: do not compare slices against nil
Comparing slices against nil currently causes the slice to escape, due to a limitation in LLVM 8. This leads to lots of unnecessary heap allocations. With LLVM 9 and some modifications to TinyGo, this should be fixed. However, this commit is an easy win right now. Returning an error when both slices are nil is not necessary, when the check is left out it should just do nothing. For updating an SPI screen using the st7735 driver, this results in a ~7% performance win.
1 parent 832f301 commit 4164c39

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

src/machine/machine_nrf.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
)
1010

1111
var (
12-
ErrTxSlicesRequired = errors.New("SPI Tx requires a write or read slice, or both")
1312
ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
1413
)
1514

@@ -348,10 +347,6 @@ func (spi SPI) Transfer(w byte) (byte, error) {
348347
// spi.Tx(nil, rx)
349348
//
350349
func (spi SPI) Tx(w, r []byte) error {
351-
if w == nil && r == nil {
352-
return ErrTxSlicesRequired
353-
}
354-
355350
var err error
356351

357352
switch {

0 commit comments

Comments
 (0)