diff options
Diffstat (limited to 'sortFunc.go')
| -rw-r--r-- | sortFunc.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/sortFunc.go b/sortFunc.go index e12db51..361462b 100644 --- a/sortFunc.go +++ b/sortFunc.go @@ -57,18 +57,18 @@ func (pf *File) selectAllFunc(w io.Writer) { var BASE string = pf.Base.Name var LOCK string = pf.Bases.Lockname - fmt.Fprintln(w, "func (all *"+BASES+") All() *"+BASE+"Iterator {") - fmt.Fprintln(w, " "+BASE+"Pointers := all.selectAll"+BASE+"()") + fmt.Fprintln(w, "func (x *"+BASES+") All() *"+BASE+"Iterator {") + fmt.Fprintln(w, " "+BASE+"Pointers := x.selectAll"+BASE+"()") fmt.Fprintln(w, "") fmt.Fprintln(w, " iterator := New"+BASE+"Iterator("+BASE+"Pointers)") fmt.Fprintln(w, " return iterator") fmt.Fprintln(w, "}") fmt.Fprintln(w, "") - fmt.Fprintln(w, "func (all *"+BASES+") Len() int {") + fmt.Fprintln(w, "func (x *"+BASES+") Len() int {") fmt.Fprintln(w, " "+LOCK+".RLock()") fmt.Fprintln(w, " defer "+LOCK+".RUnlock()") fmt.Fprintln(w, "") - fmt.Fprintln(w, " return len(all."+BASES+")") + fmt.Fprintln(w, " return len(x."+BASES+")") fmt.Fprintln(w, "}") fmt.Fprintln(w, "") } @@ -78,8 +78,8 @@ func (pf *File) sortByFunc(w io.Writer) { var BASE string = pf.Base.Name for _, SORT := range pf.Base.Sort { - fmt.Fprintln(w, "func (all *"+BASES+") SortBy"+SORT+"() *"+BASE+"Iterator {") - fmt.Fprintln(w, " things := all.selectAll"+BASE+"()") + fmt.Fprintln(w, "func (x *"+BASES+") SortBy"+SORT+"() *"+BASE+"Iterator {") + fmt.Fprintln(w, " things := x.selectAll"+BASE+"()") fmt.Fprintln(w, "") fmt.Fprintln(w, " sort.Sort("+BASE+""+SORT+"(things))") fmt.Fprintln(w, "") @@ -103,14 +103,14 @@ func (pf *File) iterSelect(w io.Writer) { var LOCK string = pf.Bases.Lockname fmt.Fprintln(w, "// safely returns a slice of pointers to the "+BASE+" protobufs") - fmt.Fprintln(w, "func (all *"+BASES+") selectAll"+BASE+"() []*"+BASE+" {") + fmt.Fprintln(w, "func (x *"+BASES+") selectAll"+BASE+"() []*"+BASE+" {") fmt.Fprintln(w, " "+LOCK+".RLock()") fmt.Fprintln(w, " defer "+LOCK+".RUnlock()") fmt.Fprintln(w, "") fmt.Fprintln(w, " // Create a new slice to hold pointers to each "+BASE+"") fmt.Fprintln(w, " var tmp []*"+BASE+"") - fmt.Fprintln(w, " tmp = make([]*"+BASE+", len(all."+BASES+"))") - fmt.Fprintln(w, " for i, p := range all."+BASES+" {") + fmt.Fprintln(w, " tmp = make([]*"+BASE+", len(x."+BASES+"))") + fmt.Fprintln(w, " for i, p := range x."+BASES+" {") fmt.Fprintln(w, " tmp[i] = p // Copy pointers for safe iteration") fmt.Fprintln(w, " }") fmt.Fprintln(w, "") |
