Reverse string without allocating a temporary buffer