goderive icon indicating copy to clipboard operation
goderive copied to clipboard

Create plugin for DeepCoyp for nested ptr recursion, that can copy cycles

Open lx-world opened this issue 3 years ago • 5 comments

type A struct {
	B *B
}

type B struct {
	A *A
}

func (a *A) Clone() *A {
	a1 := &A{B: &B{}}
	a1.B.A = a1

	tp := &A{}
	deriveDeepCopyA(tp, a1)
	return tp
}

lx-world avatar Oct 08 '21 12:10 lx-world

Yes good catch. Currently it is expected the deriveDeepCopy does not get looped structures, but I am open to ideas to address this and make the function more robust.

How do you propose to fix this, as in what do you propose the generated deriveDeepCopyA's code should look like?

awalterschulze avatar Oct 11 '21 11:10 awalterschulze

Yes good catch. Currently it is expected the deriveDeepCopy does not get looped structures, but I am open to ideas to address this and make the function more robust.

How do you propose to fix this, as in what do you propose the generated deriveDeepCopyA's code should look like?

I found this: https://github.com/huandu/go-clone/blob/master/clone.go ----> Slowly()

lx-world avatar Oct 12 '21 02:10 lx-world

Fair, yes we could made a slowly version of deepcopy. Would you be interested in contributing the new plugin?

awalterschulze avatar Oct 12 '21 06:10 awalterschulze

Fair, yes we could made a slowly version of deepcopy. Would you be interested in contributing the new plugin?

Let me try

lx-world avatar Oct 15 '21 11:10 lx-world