This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone.go
118 lines (103 loc) · 2.89 KB
/
clone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package goal
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x V) Clone() V {
if x.kind != valBoxed {
return x
}
switch xv := x.bv.(type) {
case RefCounter:
x.bv = xv.Clone()
return x
default:
return x
}
}
func (e *errV) Clone() BV {
if e.V.HasRC() {
return &errV{V: e.V.Clone()}
}
return e
}
// sclone returns a shallow clone of an array. It may share memory with the parent if it
// was reusable. Any parent flags are reset.
func (x *A[T]) sclone() *A[T] {
if x.reusable() {
x.flags = flagNone
return x
}
r := &A[T]{elts: make([]T, len(x.elts))}
copy(r.elts, x.elts)
return r
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x *AB) Clone() BV {
return (*AB)((*A[byte])(x).sclone())
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x *AI) Clone() BV {
return (*AI)((*A[int64])(x).sclone())
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x *AF) Clone() BV {
return (*AF)((*A[float64])(x).sclone())
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x *AS) Clone() BV {
return (*AS)((*A[string])(x).sclone())
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (x *AV) Clone() BV {
x = (*AV)((*A[V])(x).sclone())
for i, xi := range x.elts {
x.elts[i] = xi.Clone()
}
return x
}
// Clone returns a clone of the value. Note that the cloned value might still
// share some structures with its parent if they're deemed reusable.
func (d *D) Clone() BV {
return &D{keys: d.keys.Clone().(Array), values: d.values.Clone().(Array)}
}
func (p *projection) Clone() BV {
np := &projection{Fun: p.Fun.Clone(), Args: make([]V, len(p.Args))}
for i, arg := range p.Args {
np.Args[i] = arg.Clone()
}
return np
}
func (p *projectionFirst) Clone() BV {
if p.Fun.HasRC() || p.Arg.HasRC() {
return &projectionFirst{Fun: p.Fun.Clone(), Arg: p.Arg.Clone()}
}
return p
}
func (p *projectionMonad) Clone() BV {
if p.Fun.HasRC() {
return &projectionMonad{Fun: p.Fun.Clone()}
}
return p
}
func (r *derivedVerb) Clone() BV {
if r.Arg.HasRC() {
return &derivedVerb{Fun: r.Fun, Arg: r.Arg.Clone()}
}
return r
}
func (r *replacer) Clone() BV {
if r.oldnew.reusable() {
return r
}
return &replacer{r: r.r, oldnew: (*AS)((*A[string])(r.oldnew).sclone())}
}
func (r *rxReplacer) Clone() BV {
if r.repl.HasRC() {
return &rxReplacer{r: r.r, repl: r.repl.Clone()}
}
return r
}