iface

package
v0.3.39 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: LGPL-2.1 Imports: 4 Imported by: 2

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 MakeFaceT added in v0.2.91

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

MakeFaceT 创建Face,不使用Cache

func MakeFaceTC added in v0.2.91

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

MakeFaceTC 创建Face,使用Cache,传入接口与Cache

func MakeFaceTReflectC added in v0.2.91

func MakeFaceTReflectC[T, C any](iface T) Face[T]

MakeFaceTReflectC 创建Face,使用Cache,自动反射Cache类型

func (*Face[T]) IsNil

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

IsNil 是否为空

type FaceAny

type FaceAny = Face[any]

FaceAny any face

func MakeFaceAny

func MakeFaceAny[C any](iface C) FaceAny

MakeFaceAny 创建FaceAny,使用Cache,不使用接口

Jump to

Keyboard shortcuts

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