1 | //===-- runtime/buffer.cpp ------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "buffer.h" |
10 | #include <algorithm> |
11 | |
12 | namespace Fortran::runtime::io { |
13 | |
14 | // Here's a very old trick for shifting circular buffer data cheaply |
15 | // without a need for a temporary array. |
16 | void LeftShiftBufferCircularly( |
17 | char *buffer, std::size_t bytes, std::size_t shift) { |
18 | // Assume that we start with "efgabcd" and the left shift is 3. |
19 | std::reverse(first: buffer, last: buffer + shift); // "gfeabcd" |
20 | std::reverse(first: buffer, last: buffer + bytes); // "dcbaefg" |
21 | std::reverse(first: buffer, last: buffer + bytes - shift); // "abcdefg" |
22 | } |
23 | } // namespace Fortran::runtime::io |
24 | |