c2047754c3
Compiler changes: * Change map assignment to use mapassign and assign value directly. * Change string iteration to use decoderune, faster for ASCII strings. * Change makeslice to take int, and use makeslice64 for larger values. * Add new noverflow field to hmap struct used for maps. Unresolved problems, to be fixed later: * Commented out test in go/types/sizes_test.go that doesn't compile. * Commented out reflect.TestStructOf test for padding after zero-sized field. Reviewed-on: https://go-review.googlesource.com/35231 gotools/: Updates for Go 1.8rc1. * Makefile.am (go_cmd_go_files): Add bug.go. (s-zdefaultcc): Write defaultPkgConfig. * Makefile.in: Rebuild. From-SVN: r244456
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package sync_test
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
var bufPool = sync.Pool{
|
|
New: func() interface{} {
|
|
// The Pool's New function should generally only return pointer
|
|
// types, since a pointer can be put into the return interface
|
|
// value without an allocation:
|
|
return new(bytes.Buffer)
|
|
},
|
|
}
|
|
|
|
// timeNow is a fake version of time.Now for tests.
|
|
func timeNow() time.Time {
|
|
return time.Unix(1136214245, 0)
|
|
}
|
|
|
|
func Log(w io.Writer, key, val string) {
|
|
b := bufPool.Get().(*bytes.Buffer)
|
|
b.Reset()
|
|
// Replace this with time.Now() in a real logger.
|
|
b.WriteString(timeNow().UTC().Format(time.RFC3339))
|
|
b.WriteByte(' ')
|
|
b.WriteString(key)
|
|
b.WriteByte('=')
|
|
b.WriteString(val)
|
|
w.Write(b.Bytes())
|
|
bufPool.Put(b)
|
|
}
|
|
|
|
func ExamplePool() {
|
|
Log(os.Stdout, "path", "/search?q=flowers")
|
|
// Output: 2006-01-02T15:04:05Z path=/search?q=flowers
|
|
}
|