Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature Request: enable preheat by default #19

@FlyingOnion

Description

@FlyingOnion

Thanks for your contribution, and I do have a suggestion which may make this library better.

I'm using this library to write a code generator with generics, and I cannot predict which specific type the user may call.

type DeepCopyGen[T any] interface {
	DeepCopyInto(*T)
}

func DeepCopy[T any](in, out *T) {
	var _in any = in
	if d, ok := _in.(DeepCopyGen[T]); ok {
		// use deepcopy-gen
		d.DeepCopyInto(out)
		return
	}
	// Have to call pcopy.Preheat each time
	pcopy.Copy(in, out, pcopy.WithUsePreheat())
}

if pcopy.Copy enables preheat by default, then things go easy. Just call pcopy.Copy(in, out) is enough.

The process could be as follows:

  1. split getFromCacheSetAndRun into get and run, the get function returns (*allFieldFunc, bool)
  2. if get returns nil, false, call newAllFieldFunc and saveToCache
  3. call *allFieldFunc.do
  4. the opts ...Option argument can be removed

What do you think? @guonaihong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions