xref: /aosp_15_r20/external/pdfium/core/fxcrt/span_util.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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 "core/fxcrt/fx_memcpy_wrappers.h"
9 #include "third_party/base/check_op.h"
10 #include "third_party/base/containers/span.h"
11 
12 namespace fxcrt {
13 
14 // Bounds-checked copies from spans into spans.
15 template <typename T,
16           typename U,
17           typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
spancpy(pdfium::span<T> dst,pdfium::span<U> src)18 void spancpy(pdfium::span<T> dst, pdfium::span<U> src) {
19   CHECK_GE(dst.size_bytes(), src.size_bytes());
20   FXSYS_memcpy(dst.data(), src.data(), src.size_bytes());
21 }
22 
23 // Bounds-checked moves from spans into spans.
24 template <typename T,
25           typename U,
26           typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
spanmove(pdfium::span<T> dst,pdfium::span<U> src)27 void spanmove(pdfium::span<T> dst, pdfium::span<U> src) {
28   CHECK_GE(dst.size_bytes(), src.size_bytes());
29   FXSYS_memmove(dst.data(), src.data(), src.size_bytes());
30 }
31 
32 // Bounds-checked sets into spans.
33 template <typename T>
spanset(pdfium::span<T> dst,uint8_t val)34 void spanset(pdfium::span<T> dst, uint8_t val) {
35   FXSYS_memset(dst.data(), val, dst.size_bytes());
36 }
37 
38 // Bounds-checked zeroing of spans.
39 template <typename T>
spanclr(pdfium::span<T> dst)40 void spanclr(pdfium::span<T> dst) {
41   FXSYS_memset(dst.data(), 0, dst.size_bytes());
42 }
43 
44 }  // namespace fxcrt
45 
46 #endif  // CORE_FXCRT_SPAN_UTIL_H_
47