1//===- Arrays.h ------------------------------------------------*- C++ -*-===//
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#ifndef LLD_ARRAYS_H
10#define LLD_ARRAYS_H
11
12#include "llvm/ADT/ArrayRef.h"
13
14#include <vector>
15
16namespace lld {
17// Split one uint8 array into small pieces of uint8 arrays.
18inline std::vector<llvm::ArrayRef<uint8_t>> split(llvm::ArrayRef<uint8_t> arr,
19 size_t chunkSize) {
20 std::vector<llvm::ArrayRef<uint8_t>> ret;
21 while (arr.size() > chunkSize) {
22 ret.push_back(x: arr.take_front(N: chunkSize));
23 arr = arr.drop_front(N: chunkSize);
24 }
25 if (!arr.empty())
26 ret.push_back(x: arr);
27 return ret;
28}
29
30} // namespace lld
31
32#endif
33

source code of lld/include/lld/Common/Arrays.h