A couple potential optimizations inspired by comment 4 in PR6773.