Add support for manually defined DeepCopy methods

In bringing back Clayton's PR piece-by-piece this was almost as easy to
implement as his version, and is much more like what I think we should be
doing.

Specifically, any time which defines a .DeepCopy() method will have that method
called preferentially.  Otherwise we generate our own functions for
deep-copying.  This affected exactly one type - resource.Quantity.  In applying
this heuristic, several places in the generated code were simplified.

To achieve this I had to convert types.Type.Methods from a slice to a map,
which seems correct anyway (to do by-name lookups).
This commit is contained in:
Tim Hockin
2016-06-29 02:08:23 -07:00
parent be481060ea
commit 57c3196914
34 changed files with 1057 additions and 1996 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +0,0 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package resource
import (
inf "gopkg.in/inf.v0"
conversion "k8s.io/kubernetes/pkg/conversion"
)
func DeepCopy_resource_Quantity(in Quantity, out *Quantity, c *conversion.Cloner) error {
*out = in
if in.d.Dec != nil {
tmp := &inf.Dec{}
out.d.Dec = tmp.Set(in.d.Dec)
}
return nil
}

View File

@@ -385,6 +385,16 @@ func ParseQuantity(str string) (Quantity, error) {
return Quantity{d: infDecAmount{amount}, Format: format}, nil
}
// DeepCopy returns a deep-copy of the Quantity value. Note that the method
// receiver is a value, so we can mutate it in-place and return it.
func (q Quantity) DeepCopy() Quantity {
if q.d.Dec != nil {
tmp := &inf.Dec{}
q.d.Dec = tmp.Set(q.d.Dec)
}
return q
}
// CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity).
//
// Note about BinarySI:

View File

@@ -33,6 +33,13 @@ type Time struct {
time.Time `protobuf:"-"`
}
// DeepCopy returns a deep-copy of the Time value. The underlying time.Time
// type is effectively immutable in the time API, so it is safe to
// copy-by-assign, despite the presence of (unexported) Pointer fields.
func (t Time) DeepCopy() Time {
return t
}
// NewTime returns a wrapped instance of the provided time
func NewTime(time time.Time) Time {
return Time{time}

File diff suppressed because it is too large Load Diff