Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2. public T Read<T>()
  3. {
  4. if (TypeCache<T>.CanUsePadding16)
  5. return Unsafe.As<Padding16, T>(ref _valueStorage);
  6.  
  7. return (T)_defaultStorage;
  8. }
  9.  
  10. public static class TypeCache<T>
  11. {
  12. public static readonly bool CanUsePadding16;
  13.  
  14. static TypeCache()
  15. {
  16. CanUsePadding16 =
  17. !IsReferenceOrContainsReferences(typeof(T)) && Unsafe.SizeOf<T>() <= 16;
  18. }
  19.  
  20. private static bool IsReferenceOrContainsReferences(Type type)
  21. {
  22. // Custom implementation using reflection
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement