blob: 15c83bfd249232d55fcaa46159521b4739820610 [file] [log] [blame]
Diana Picus651f58b2021-09-02 08:14:011//===-- runtime/buffer.cpp ------------------------------------------------===//
peter klauslerf7be2512020-01-24 00:59:272//
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
12namespace 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.
16void 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.
Tim Keith1f879002020-03-29 04:00:1619 std::reverse(buffer, buffer + shift); // "gfeabcd"
20 std::reverse(buffer, buffer + bytes); // "dcbaefg"
21 std::reverse(buffer, buffer + bytes - shift); // "abcdefg"
peter klauslerf7be2512020-01-24 00:59:2722}
Tim Keith1f879002020-03-29 04:00:1623} // namespace Fortran::runtime::io