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:
Ayke van Laethem
2020-04-04 14:33:29 +02:00
committed by Ron Evans
parent 9f8715c143
commit b8f5627c9f
8 changed files with 70 additions and 55 deletions
+3 -1
View File
@@ -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