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