1 // Copyright 2021 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CORE_FXCRT_SPAN_UTIL_H_
6 #define CORE_FXCRT_SPAN_UTIL_H_
7
8 #include <string.h>
9
10 #include "third_party/base/check_op.h"
11 #include "third_party/base/span.h"
12
13 namespace fxcrt {
14
15 // Bounds-checked copies from spans into spans.
16 template <typename T,
17 typename U,
18 typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
spancpy(pdfium::span<T> dst,pdfium::span<U> src)19 void spancpy(pdfium::span<T> dst, pdfium::span<U> src) {
20 CHECK_GE(dst.size_bytes(), src.size_bytes());
21 memcpy(dst.data(), src.data(), src.size_bytes());
22 }
23
24 // Bounds-checked moves from spans into spans.
25 template <typename T,
26 typename U,
27 typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
spanmove(pdfium::span<T> dst,pdfium::span<U> src)28 void spanmove(pdfium::span<T> dst, pdfium::span<U> src) {
29 CHECK_GE(dst.size_bytes(), src.size_bytes());
30 memmove(dst.data(), src.data(), src.size_bytes());
31 }
32
33 // Bounds-checked sets into spans.
34 template <typename T>
spanset(pdfium::span<T> dst,uint8_t val)35 void spanset(pdfium::span<T> dst, uint8_t val) {
36 memset(dst.data(), val, dst.size_bytes());
37 }
38
39 // Bounds-checked zeroing of spans.
40 template <typename T>
spanclr(pdfium::span<T> dst)41 void spanclr(pdfium::span<T> dst) {
42 memset(dst.data(), 0, dst.size_bytes());
43 }
44
45 } // namespace fxcrt
46
47 #endif // CORE_FXCRT_SPAN_UTIL_H_
48