Permalink
Browse files

Optimize bounds checking's ternary operator use

By supplying a value on both sides of the check, browsers are able to
always assume a value will exist (even if it is bypassed by the thrown
error), and optimize accordingly.
  • Loading branch information...
1 parent acd7601 commit edbab3ce7c64b93a8f11731207d8546be236b65f @jbowes jbowes committed with neelance Jan 26, 2017
Showing with 1 addition and 1 deletion.
  1. +1 −1 compiler/utils.go
View
@@ -623,7 +623,7 @@ func rangeCheck(pattern string, constantIndex, array bool) string {
if !constantIndex {
check = "(%2f < 0 || " + check + ")"
}
- return "(" + check + ` ? $throwRuntimeError("index out of range") : ` + pattern + ")"
+ return "(" + check + ` ? ($throwRuntimeError("index out of range"), undefined) : ` + pattern + ")"
}
func endsWithReturn(stmts []ast.Stmt) bool {

0 comments on commit edbab3c

Please sign in to comment.