Skip to content

Commit

Permalink
Skylark interpreter optimization
Browse files Browse the repository at this point in the history
Special-case the return statement to avoid throwing an exception.

--
MOS_MIGRATED_REVID=106488391
  • Loading branch information
laurentlb authored and dslomov committed Oct 28, 2015
1 parent 1ffbbdd commit b655167
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ public Object call(Object[] arguments, FuncallExpression ast, Environment env)

try {
for (Statement stmt : statements) {
stmt.exec(env);
if (stmt instanceof ReturnStatement) {
// Performance optimization.
// Executing the statement would throw an exception, which is slow.
return ((ReturnStatement) stmt).getReturnExpression().eval(env);
} else {
stmt.exec(env);
}
}
} catch (ReturnStatement.ReturnException e) {
return e.getValue();
Expand Down

0 comments on commit b655167

Please sign in to comment.