mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 04:23:41 +00:00
compiler: inline slice bounds checking
This improves code size in all tests by about 1% and up to 5% in some cases, likely because LLVM can better reason about inline bounds checks.
This commit is contained in:
committed by
Ron Evans
parent
051ad07755
commit
bd6a7b69ce
+6
-25
@@ -32,33 +32,14 @@ func nilpanic() {
|
||||
runtimePanic("nil pointer dereference")
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup.
|
||||
func lookupBoundsCheck(length uintptr, index int) {
|
||||
if index < 0 || index >= int(length) {
|
||||
runtimePanic("index out of range")
|
||||
}
|
||||
// Panic when trying to acces an array or slice out of bounds.
|
||||
func lookuppanic() {
|
||||
runtimePanic("index out of range")
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup.
|
||||
// Supports 64-bit indexes.
|
||||
func lookupBoundsCheckLong(length uintptr, index int64) {
|
||||
if index < 0 || index >= int64(length) {
|
||||
runtimePanic("index out of range")
|
||||
}
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.Slice.
|
||||
func sliceBoundsCheck(capacity, low, high uintptr) {
|
||||
if !(0 <= low && low <= high && high <= capacity) {
|
||||
runtimePanic("slice out of range")
|
||||
}
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.Slice. Supports 64-bit indexes.
|
||||
func sliceBoundsCheck64(capacity uintptr, low, high uint64) {
|
||||
if !(0 <= low && low <= high && high <= uint64(capacity)) {
|
||||
runtimePanic("slice out of range")
|
||||
}
|
||||
// Panic when trying to slice a slice out of bounds.
|
||||
func slicepanic() {
|
||||
runtimePanic("slice out of range")
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.MakeSlice.
|
||||
|
||||
Reference in New Issue
Block a user