Using a custom immutable iterator type seems to be faster.