GenBCode: cleanup optimizations

Method-level cleanup optimizations.

See individual commit messages.
`foreachWithIndex(list.asScala)(...)` is more efficient.