Rewrote ByteVector::replace() simpler (fix for the issue #308)

This aims to fix the bug reported by @nerijus at the issue #308.

The cause seems simple. Probably, the bounds check failed when the vector was shrunk. 
But I drastically rewrote ```ByteVector::replace()``` function. Because I found that the function can be rewritten much simpler while investigating the bug.