Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Macros | Functions | Variables
SkUtils.h File Reference
#include "include/private/base/SkAttributes.h"
#include <cstring>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  SkHexadecimalDigits
 

Macros

#define SK_FP_SAFE_ABI
 

Functions

template<typename T , typename P >
static SK_ALWAYS_INLINE T SK_FP_SAFE_ABI sk_unaligned_load (const P *ptr)
 
template<typename T , typename P >
static SK_ALWAYS_INLINE void SK_FP_SAFE_ABI sk_unaligned_store (P *ptr, T val)
 
template<typename Dst , typename Src >
static SK_ALWAYS_INLINE Dst SK_FP_SAFE_ABI sk_bit_cast (const Src &src)
 

Variables

const char SkHexadecimalDigits::gUpper [16]
 
const char SkHexadecimalDigits::gLower [16]
 

Macro Definition Documentation

◆ SK_FP_SAFE_ABI

#define SK_FP_SAFE_ABI

Definition at line 42 of file SkUtils.h.

Function Documentation

◆ sk_bit_cast()

template<typename Dst , typename Src >
static SK_ALWAYS_INLINE Dst SK_FP_SAFE_ABI sk_bit_cast ( const Src &  src)
static

Definition at line 68 of file SkUtils.h.

68 {
69 static_assert(sizeof(Dst) == sizeof(Src));
70 static_assert(std::is_trivially_copyable<Dst>::value);
71 static_assert(std::is_trivially_copyable<Src>::value);
72 return sk_unaligned_load<Dst>(&src);
73}

◆ sk_unaligned_load()

template<typename T , typename P >
static SK_ALWAYS_INLINE T SK_FP_SAFE_ABI sk_unaligned_load ( const P *  ptr)
static

Definition at line 46 of file SkUtils.h.

46 {
47 static_assert(std::is_trivially_copyable_v<P> || std::is_void_v<P>);
48 static_assert(std::is_trivially_copyable_v<T>);
49 T val;
50 // gcc's class-memaccess sometimes triggers when:
51 // - `T` is trivially copyable but
52 // - `T` is non-trivial (e.g. at least one eligible default constructor is
53 // non-trivial).
54 // Use `reinterpret_cast<const void*>` to explicit suppress this warning; a
55 // trivially copyable type is safe to memcpy from/to.
56 memcpy(&val, static_cast<const void*>(ptr), sizeof(val));
57 return val;
58}
#define T

◆ sk_unaligned_store()

template<typename T , typename P >
static SK_ALWAYS_INLINE void SK_FP_SAFE_ABI sk_unaligned_store ( P *  ptr,
T  val 
)
static

Definition at line 61 of file SkUtils.h.

61 {
62 static_assert(std::is_trivially_copyable<T>::value);
63 memcpy(ptr, &val, sizeof(val));
64}