diff options
| author | Russ Cox <rsc@golang.org> | 2012-06-27 16:52:36 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2012-06-27 16:52:36 -0400 |
| commit | 9525372e31f6bad979a5f472aecfc24af34f28d0 (patch) | |
| tree | 3d693efc78a26053dede004a634e6e2288c09cd0 /src/pkg/path/filepath/path_test.go | |
| parent | 5a5e698c8fceec38c34f86375dcd44fb1a7a8939 (diff) | |
| download | go-9525372e31f6bad979a5f472aecfc24af34f28d0.tar.xz | |
path/filepath: avoid allocation in Clean of cleaned path
Alternative to https://golang.org/cl/6330044.
Fixes #3681.
R=golang-dev, r, hanwen, iant
CC=golang-dev
https://golang.org/cl/6335056
Diffstat (limited to 'src/pkg/path/filepath/path_test.go')
| -rw-r--r-- | src/pkg/path/filepath/path_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go index cb84d98b47..ec6af4db7e 100644 --- a/src/pkg/path/filepath/path_test.go +++ b/src/pkg/path/filepath/path_test.go @@ -99,6 +99,24 @@ func TestClean(t *testing.T) { if s := filepath.Clean(test.path); s != test.result { t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result) } + if s := filepath.Clean(test.result); s != test.result { + t.Errorf("Clean(%q) = %q, want %q", test.result, s, test.result) + } + } + + var ms runtime.MemStats + runtime.ReadMemStats(&ms) + allocs := -ms.Mallocs + const rounds = 100 + for i := 0; i < rounds; i++ { + for _, test := range tests { + filepath.Clean(test.result) + } + } + runtime.ReadMemStats(&ms) + allocs += ms.Mallocs + if allocs >= rounds { + t.Errorf("Clean cleaned paths: %d allocations per test round, want zero", allocs/rounds) } } |
