diff options
Diffstat (limited to 'sort.go')
| -rw-r--r-- | sort.go | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -117,13 +117,13 @@ func (pf *File) iterSelect(w io.Writer) { 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 aStuff []*"+BASE+"") - fmt.Fprintln(w, " aStuff = make([]*"+BASE+", len(all."+BASES+"))") + 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, " aStuff[i] = p // Copy pointers for safe iteration") + fmt.Fprintln(w, " tmp[i] = p // Copy pointers for safe iteration") fmt.Fprintln(w, " }") fmt.Fprintln(w, "") - fmt.Fprintln(w, " return aStuff") + fmt.Fprintln(w, " return tmp") fmt.Fprintln(w, "}") } @@ -142,6 +142,7 @@ func (pf *File) appendUnique(w io.Writer) { LOCK = pf.Bases.Lockname } + // append check for every key fmt.Fprintln(w, "// enforces "+BASE+" is unique") fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique(newP *"+BASE+") bool {") fmt.Fprintln(w, " "+LOCK+".RLock()") @@ -160,6 +161,7 @@ func (pf *File) appendUnique(w io.Writer) { fmt.Fprintln(w, "}") fmt.Fprintln(w, "") + // append for single keys for _, KEY := range pf.Base.Unique { fmt.Fprintln(w, "// enforces "+BASE+" is unique") fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique"+KEY+"(newP *"+BASE+") bool {") @@ -177,6 +179,17 @@ func (pf *File) appendUnique(w io.Writer) { fmt.Fprintln(w, "}") fmt.Fprintln(w, "") } + + // append -- no check at all + fmt.Fprintln(w, "// just a simple Append() with no checking (but still uses the mutex lock)") + fmt.Fprintln(w, "func (all *"+MSG+") Append(newP *"+BASE+") bool {") + fmt.Fprintln(w, " "+LOCK+".RLock()") + fmt.Fprintln(w, " defer "+LOCK+".RUnlock()") + fmt.Fprintln(w, "") + fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)") + fmt.Fprintln(w, " return true") + fmt.Fprintln(w, "}") + fmt.Fprintln(w, "") } func iterReplace(w io.Writer, names map[string]string) { |
