I found the original implementation quite hard to follow, and I believe this is functionally identical. PiperOrigin-RevId: 270237641