diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-01-18 19:04:36 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-18 19:04:36 +0000 |
commit | 4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch) | |
tree | f12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/expvar | |
parent | 225220d668dafb8262db7012bced688acbe63b33 (diff) | |
download | gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2 |
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019
gotools/:
* Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release.
(GOTOOLS_TEST_TIMEOUT): Increase to 600.
(check-runtime): Export LD_LIBRARY_PATH before computing GOARCH
and GOOS.
(check-vet): Copy golang.org/x/tools into check-vet-dir.
* Makefile.in: Regenerate.
gcc/testsuite/:
* go.go-torture/execute/names-1.go: Stop using debug/xcoff, which
is no longer externally visible.
From-SVN: r268084
Diffstat (limited to 'libgo/go/expvar')
-rw-r--r-- | libgo/go/expvar/expvar.go | 15 | ||||
-rw-r--r-- | libgo/go/expvar/expvar_test.go | 37 |
2 files changed, 50 insertions, 2 deletions
diff --git a/libgo/go/expvar/expvar.go b/libgo/go/expvar/expvar.go index 174873a..976b300 100644 --- a/libgo/go/expvar/expvar.go +++ b/libgo/go/expvar/expvar.go @@ -137,7 +137,7 @@ func (v *Map) Init() *Map { return v } -// updateKeys updates the sorted list of keys in v.keys. +// addKey updates the sorted list of keys in v.keys. func (v *Map) addKey(key string) { v.keysMu.Lock() defer v.keysMu.Unlock() @@ -199,6 +199,17 @@ func (v *Map) AddFloat(key string, delta float64) { } } +// Deletes the given key from the map. +func (v *Map) Delete(key string) { + v.keysMu.Lock() + defer v.keysMu.Unlock() + i := sort.SearchStrings(v.keys, key) + if i < len(v.keys) && key == v.keys[i] { + v.keys = append(v.keys[:i], v.keys[i+1:]...) + v.m.Delete(key) + } +} + // Do calls f for each entry in the map. // The map is locked during the iteration, // but existing entries may be concurrently updated. @@ -221,7 +232,7 @@ func (v *String) Value() string { return p } -// String implements the Val interface. To get the unquoted string +// String implements the Var interface. To get the unquoted string // use Value. func (v *String) String() string { s := v.Value() diff --git a/libgo/go/expvar/expvar_test.go b/libgo/go/expvar/expvar_test.go index 728e763..804b56c 100644 --- a/libgo/go/expvar/expvar_test.go +++ b/libgo/go/expvar/expvar_test.go @@ -183,6 +183,43 @@ func TestMapInit(t *testing.T) { } } +func TestMapDelete(t *testing.T) { + RemoveAll() + colors := NewMap("bike-shed-colors") + + colors.Add("red", 1) + colors.Add("red", 2) + colors.Add("blue", 4) + + n := 0 + colors.Do(func(KeyValue) { n++ }) + if n != 2 { + t.Errorf("after two Add calls with distinct keys, Do should invoke f 2 times; got %v", n) + } + + colors.Delete("red") + n = 0 + colors.Do(func(KeyValue) { n++ }) + if n != 1 { + t.Errorf("removed red, Do should invoke f 1 times; got %v", n) + } + + colors.Delete("notfound") + n = 0 + colors.Do(func(KeyValue) { n++ }) + if n != 1 { + t.Errorf("attempted to remove notfound, Do should invoke f 1 times; got %v", n) + } + + colors.Delete("blue") + colors.Delete("blue") + n = 0 + colors.Do(func(KeyValue) { n++ }) + if n != 0 { + t.Errorf("all keys removed, Do should invoke f 0 times; got %v", n) + } +} + func TestMapCounter(t *testing.T) { RemoveAll() colors := NewMap("bike-shed-colors") |