Since it's already a pretty low-level call, I'd go with a while loop instead of a for loop to make sure it's fast enough.

tailrec is pretty much the second fastest way to make a "loop" in Scala (behind while), but it does look overkill in that instance.