Sync changes to internal version:
- use append built-in
- remove NewT from commentary
- some idiom changes
R=r
CC=golang-dev
http://codereview.appspot.com/2926042
diff --git a/compiler/generator/generator.go b/compiler/generator/generator.go
index f64b5d4..2f9aebe 100644
--- a/compiler/generator/generator.go
+++ b/compiler/generator/generator.go
@@ -71,14 +71,7 @@
// RegisterPlugin installs a (second-order) plugin to be run when the Go output is generated.
// It is typically called during initialization.
func RegisterPlugin(p Plugin) {
- n := len(plugins)
- if cap(plugins) == n {
- nplugins := make([]Plugin, n, n+10) // very unlikely to need more than this
- copy(nplugins, plugins)
- plugins = nplugins
- }
- plugins = plugins[0 : n+1]
- plugins[n] = p
+ plugins = append(plugins, p)
}
// Each type we import as a protocol buffer (other than FileDescriptorProto) needs
@@ -438,14 +431,7 @@
d.ext[i] = &ExtensionDescriptor{common{File: file}, field, d}
}
- if len(sl) == cap(sl) {
- nsl := make([]*Descriptor, len(sl), 2*len(sl))
- copy(nsl, sl)
- sl = nsl
- }
- sl = sl[0 : len(sl)+1]
- sl[len(sl)-1] = d
- return sl
+ return append(sl, d)
}
// Return a slice of all the Descriptors defined within this file
@@ -469,14 +455,7 @@
// Construct the EnumDescriptor and add it to the slice
func addEnumDescriptor(sl []*EnumDescriptor, desc *descriptor.EnumDescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto) []*EnumDescriptor {
- if len(sl) == cap(sl) {
- nsl := make([]*EnumDescriptor, len(sl), 2*len(sl))
- copy(nsl, sl)
- sl = nsl
- }
- sl = sl[0 : len(sl)+1]
- sl[len(sl)-1] = &EnumDescriptor{common{File: file}, desc, parent, nil}
- return sl
+ return append(sl, &EnumDescriptor{common{File: file}, desc, parent, nil})
}
// Return a slice of all the EnumDescriptors defined within this file