Code Monkey home page Code Monkey logo

pcopy's People

Contributors

dependabot[bot] avatar guonaihong avatar wangxin008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pcopy's Issues

性能压测

和src数据序列化成json。json反序列化到struct或者map,哪个快?

性能优化版本计划

6.15或者7月初
开始下个版本的性能优化,先尝试缓存解码器的思路。
使用指针优化

Feature Request: enable preheat by default

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

Changlog

草稿

0.普通递归拷贝

deepcopy.Copy(dst, src).Do()

1.控制拷贝层次,下面结构体只拷贝一层

deepcopy.Copy().MaxDepth(1).Do()

2.只拷贝指定tag的字段

deepcopy.Copy().RegisterTagName("copy").Do()

3.只拷贝string和int类型

deepcopy.Copy().OnlyType(reflect.String, reflect.Int).Do()

4.支持字段选择

deepcopy.Copy().OnlyField("id", "idx").Do()
deepcopy.Copy().OnlyField(".struct2", ".struct3").Do()

5.支持效验器,不符合要求的数据不copy

deepcopy.Copy().NeeValid(deepcopy.String()).Do()

TODO

第3,4,5条暂时不实现。

slice in struct deepcopy failed

import (
	"testing"

	"github.com/antlabs/deepcopy"
)

func TestPointerCopy(t *testing.T) {
	type A struct {
		p []int
	}

	src := A{[]int{1}}
	t.Logf("%v", src)
	var dst A
	deepcopy.Copy(&dst, &src).Do()
	t.Logf("%v", dst)
	dst.p[0] = 2 // panic here
	if src.p[0] == dst.p[0] {
		t.Fail()
	}
}

and result:

=== RUN   TestPointerCopy
--- FAIL: TestPointerCopy (0.00s)
    deepcopy_test.go:15: {[1]}
    deepcopy_test.go:18: {[]}
panic: runtime error: index out of range [0] with length 0 [recovered]
        panic: runtime error: index out of range [0] with length 0

goroutine 7 [running]:
testing.tRunner.func1(0xc0000b2200)
        /usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
panic(0x5cfc00, 0xc0000162a0)
        /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
golang_test.TestPointerCopy(0xc0000b2200)
        /home/phenix/github/phenix3443/test/golang/deepcopy_test.go:19 +0x2a6
testing.tRunner(0xc0000b2200, 0x5f3bd0)
        /usr/lib/go-1.13/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
        /usr/lib/go-1.13/src/testing/testing.go:960 +0x350
FAIL    golang_test     0.010s
FAIL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.