iface

package
v0.2.40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: LGPL-2.1 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache2Iface

func Cache2Iface[T any](c Cache) T

Cache2Iface Cache转换为接口

Types

type Cache

type Cache [2]unsafe.Pointer

Cache 因为Golang原生的接口转换性能较差,所以在某些性能要求较高的场景下,需要尽量较少接口转换。 如果必须转换接口,那么目前可用的优化方案是,在编码时已知接口类型,可以将接口转换为[2]unsafe.Pointer,使用时再转换回接口。 Cache套件就是使用此优化方案,注意不安全,在明确了解此方案时再使用。

var NilCache Cache

NilCache nil cache

func Iface2Cache

func Iface2Cache[T any](i T) Cache

Iface2Cache 接口转换为Cache

type Face

type Face[T any] struct {
	Iface T
	Cache Cache
}

Face 用于存储接口与Cache,接口可用于断言转换类型,存储器可用于转换为接口

func MakeFace

func MakeFace[T any](iface T) Face[T]

MakeFace 创建Face

func MakeFacePair added in v0.2.34

func MakeFacePair[T, C any](iface T, cache C) Face[T]

MakeFacePair 创建Face对

func (*Face[T]) IsNil

func (f *Face[T]) IsNil() bool

IsNil 是否为空

type FaceAny

type FaceAny = Face[any]

FaceAny any face

func MakeFaceAny

func MakeFaceAny[T any](iface T) FaceAny

MakeFaceAny 创建FaceAny

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL