script: Implement various microoptimizations.

This is a grab bag of various microoptimizations for script that I came across when profiling our performance on RoboHornet.

r? @jdm 

If this is changed to `assert_eq`, then maybe the `debug!` message can be dropped.