mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
machine: move errors.New calls to globals
Calling errors.New in an error path causes a heap allocation at an already unfortunate moment. It is more efficient to create these error values in globals and return these constant globals. If these errors are not used (because the related code was optimized out), the globals will also be optimized out.
This commit is contained in:
committed by
Ron Evans
parent
9f8715c143
commit
b8f5627c9f
@@ -35,6 +35,8 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var errCycleCountTooLarge = errors.New("requested cycle count is too large, overflows 24 bit counter")
|
||||
|
||||
// Run the given assembly code. The code will be marked as having side effects,
|
||||
// as it doesn't produce output and thus would normally be eliminated by the
|
||||
// optimizer.
|
||||
@@ -232,7 +234,7 @@ func SetupSystemTimer(cyclecount uint32) error {
|
||||
}
|
||||
if cyclecount&SYST_RVR_RELOAD_Msk != cyclecount {
|
||||
// The cycle refresh register is only 24 bits wide. The user-specified value will overflow.
|
||||
return errors.New("requested cycle count is too large, overflows 24 bit counter")
|
||||
return errCycleCountTooLarge
|
||||
}
|
||||
|
||||
// set refresh count
|
||||
|
||||
Reference in New Issue
Block a user