Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkSpan< T > Class Template Reference

#include <SkSpan_impl.h>

Public Member Functions

constexpr SkSpan ()
 
template<typename Integer , std::enable_if_t< std::is_integral_v< Integer >, bool > = true>
constexpr SkSpan (T *ptr, Integer size)
 
template<typename U , typename = std::enable_if_t<std::is_same_v<const U, T>>>
constexpr SkSpan (const SkSpan< U > &that)
 
constexpr SkSpan (const SkSpan &o)=default
 
template<size_t N>
constexpr SkSpan (T(&a)[N])
 
template<typename Container >
constexpr SkSpan (Container &&c)
 
 SkSpan (std::initializer_list< T > il SK_CHECK_IL_LIFETIME)
 
constexpr SkSpanoperator= (const SkSpan &that)=default
 
constexpr Toperator[] (size_t i) const
 
constexpr Tfront () const
 
constexpr Tback () const
 
constexpr Tbegin () const
 
constexpr Tend () const
 
constexpr auto rbegin () const
 
constexpr auto rend () const
 
constexpr Tdata () const
 
constexpr size_t size () const
 
constexpr bool empty () const
 
constexpr size_t size_bytes () const
 
constexpr SkSpan< Tfirst (size_t prefixLen) const
 
constexpr SkSpan< Tlast (size_t postfixLen) const
 
constexpr SkSpan< Tsubspan (size_t offset) const
 
constexpr SkSpan< Tsubspan (size_t offset, size_t count) const
 

Detailed Description

template<typename T>
class SkSpan< T >

SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own the data itself but is merely a reference, therefore you must take care with the lifetime of the underlying data.

SkSpan is a count and a pointer into existing array or data type that stores its data in contiguous memory like std::vector. Any container that works with std::size() and std::data() can be used.

SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to write the routine without overloads for all different container types.

Example: void routine(SkSpan<const int> a) { ... }

std::vector v = {1, 2, 3, 4, 5};

routine(a);

A word of caution when working with initializer_list, initializer_lists have a lifetime that is limited to the current statement. The following is correct and safe:

Example: routine({1,2,3,4,5});

The following is undefined, and will result in erratic execution:

Bad Example: initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. routine(l);

Definition at line 65 of file SkSpan_impl.h.

Constructor & Destructor Documentation

◆ SkSpan() [1/7]

template<typename T >
constexpr SkSpan< T >::SkSpan ( )
inlineconstexpr

Definition at line 67 of file SkSpan_impl.h.

67: fPtr{nullptr}, fSize{0} {}

◆ SkSpan() [2/7]

template<typename T >
template<typename Integer , std::enable_if_t< std::is_integral_v< Integer >, bool > = true>
constexpr SkSpan< T >::SkSpan ( T ptr,
Integer  size 
)
inlineconstexpr

Definition at line 70 of file SkSpan_impl.h.

70 : fPtr{ptr}, fSize{SkToSizeT(size)} {
71 SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size
72 SkASSERT(fSize < kMaxSize);
73 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
constexpr size_t size() const
Definition: SkSpan_impl.h:95

◆ SkSpan() [3/7]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_same_v<const U, T>>>
constexpr SkSpan< T >::SkSpan ( const SkSpan< U > &  that)
inlineconstexpr

Definition at line 75 of file SkSpan_impl.h.

75: fPtr(std::data(that)), fSize(std::size(that)) {}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ SkSpan() [4/7]

template<typename T >
constexpr SkSpan< T >::SkSpan ( const SkSpan< T > &  o)
constexprdefault

◆ SkSpan() [5/7]

template<typename T >
template<size_t N>
constexpr SkSpan< T >::SkSpan ( T(&)  a[N])
inlineconstexpr

Definition at line 77 of file SkSpan_impl.h.

77: SkSpan(a, N) { }
#define N
Definition: beziers.cpp:19
constexpr SkSpan()
Definition: SkSpan_impl.h:67
struct MyStruct a[10]

◆ SkSpan() [6/7]

template<typename T >
template<typename Container >
constexpr SkSpan< T >::SkSpan ( Container &&  c)
inlineconstexpr

Definition at line 79 of file SkSpan_impl.h.

79: SkSpan(std::data(c), std::size(c)) { }

◆ SkSpan() [7/7]

template<typename T >
SkSpan< T >::SkSpan ( std::initializer_list< T > il  SK_CHECK_IL_LIFETIME)
inline

Definition at line 80 of file SkSpan_impl.h.

81 : SkSpan(std::data(il), std::size(il)) {}

Member Function Documentation

◆ back()

template<typename T >
constexpr T & SkSpan< T >::back ( ) const
inlineconstexpr

Definition at line 89 of file SkSpan_impl.h.

89{ sk_collection_not_empty(this->empty()); return fPtr[fSize - 1]; }
SK_API void sk_collection_not_empty(bool empty)
Definition: SkAssert.h:175
constexpr bool empty() const
Definition: SkSpan_impl.h:96

◆ begin()

template<typename T >
constexpr T * SkSpan< T >::begin ( ) const
inlineconstexpr

Definition at line 90 of file SkSpan_impl.h.

90{ return fPtr; }

◆ data()

template<typename T >
constexpr T * SkSpan< T >::data ( ) const
inlineconstexpr

Definition at line 94 of file SkSpan_impl.h.

94{ return this->begin(); }
constexpr T * begin() const
Definition: SkSpan_impl.h:90

◆ empty()

template<typename T >
constexpr bool SkSpan< T >::empty ( ) const
inlineconstexpr

Definition at line 96 of file SkSpan_impl.h.

96{ return fSize == 0; }

◆ end()

template<typename T >
constexpr T * SkSpan< T >::end ( ) const
inlineconstexpr

Definition at line 91 of file SkSpan_impl.h.

91{ return fPtr + fSize; }

◆ first()

template<typename T >
constexpr SkSpan< T > SkSpan< T >::first ( size_t  prefixLen) const
inlineconstexpr

Definition at line 98 of file SkSpan_impl.h.

98 {
99 return SkSpan{fPtr, sk_collection_check_length(prefixLen, fSize)};
100 }
SK_API T sk_collection_check_length(T i, T size)
Definition: SkAssert.h:161

◆ front()

template<typename T >
constexpr T & SkSpan< T >::front ( ) const
inlineconstexpr

Definition at line 88 of file SkSpan_impl.h.

88{ sk_collection_not_empty(this->empty()); return fPtr[0]; }

◆ last()

template<typename T >
constexpr SkSpan< T > SkSpan< T >::last ( size_t  postfixLen) const
inlineconstexpr

Definition at line 101 of file SkSpan_impl.h.

101 {
102 return SkSpan{fPtr + (this->size() - postfixLen),
103 sk_collection_check_length(postfixLen, fSize)};
104 }

◆ operator=()

template<typename T >
constexpr SkSpan & SkSpan< T >::operator= ( const SkSpan< T > &  that)
constexprdefault

◆ operator[]()

template<typename T >
constexpr T & SkSpan< T >::operator[] ( size_t  i) const
inlineconstexpr

Definition at line 85 of file SkSpan_impl.h.

85 {
86 return fPtr[sk_collection_check_bounds(i, this->size())];
87 }
SK_API T sk_collection_check_bounds(T i, T size)
Definition: SkAssert.h:143

◆ rbegin()

template<typename T >
constexpr auto SkSpan< T >::rbegin ( ) const
inlineconstexpr

Definition at line 92 of file SkSpan_impl.h.

92{ return std::make_reverse_iterator(this->end()); }
constexpr T * end() const
Definition: SkSpan_impl.h:91

◆ rend()

template<typename T >
constexpr auto SkSpan< T >::rend ( ) const
inlineconstexpr

Definition at line 93 of file SkSpan_impl.h.

93{ return std::make_reverse_iterator(this->begin()); }

◆ size()

template<typename T >
constexpr size_t SkSpan< T >::size ( ) const
inlineconstexpr

Definition at line 95 of file SkSpan_impl.h.

95{ return fSize; }

◆ size_bytes()

template<typename T >
constexpr size_t SkSpan< T >::size_bytes ( ) const
inlineconstexpr

Definition at line 97 of file SkSpan_impl.h.

97{ return fSize * sizeof(T); }
#define T
Definition: precompiler.cc:65

◆ subspan() [1/2]

template<typename T >
constexpr SkSpan< T > SkSpan< T >::subspan ( size_t  offset) const
inlineconstexpr

Definition at line 105 of file SkSpan_impl.h.

105 {
106 return this->subspan(offset, this->size() - offset);
107 }
constexpr SkSpan< T > subspan(size_t offset) const
Definition: SkSpan_impl.h:105
SeparatedVector2 offset

◆ subspan() [2/2]

template<typename T >
constexpr SkSpan< T > SkSpan< T >::subspan ( size_t  offset,
size_t  count 
) const
inlineconstexpr

Definition at line 108 of file SkSpan_impl.h.

108 {
109 const size_t safeOffset = sk_collection_check_length(offset, fSize);
110
111 // Should read offset + count > size(), but that could overflow. We know that safeOffset
112 // is <= size, therefore the subtraction will not overflow.
113 if (count > this->size() - safeOffset) SK_UNLIKELY {
114 // The count is too large.
116 }
117 return SkSpan{fPtr + safeOffset, count};
118 }
int count
Definition: FontMgrTest.cpp:50
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SK_UNLIKELY
Definition: SkAssert.h:28

The documentation for this class was generated from the following file: