From 6d8cafd2f64fe3cd66b7530d95df066b00bdd777 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 1 Aug 2019 23:37:55 +0200 Subject: Simplify code (#149) - No need to wrap ToUpper & Fields - Simpler concatenation - Easier pointer access --- cmp/cmpopts/util_test.go | 4 ++-- cmp/report_slices.go | 2 +- cmp/report_text.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'cmp') diff --git a/cmp/cmpopts/util_test.go b/cmp/cmpopts/util_test.go index c85a282..ed0fbb1 100644 --- a/cmp/cmpopts/util_test.go +++ b/cmp/cmpopts/util_test.go @@ -806,7 +806,7 @@ func TestOptions(t *testing.T) { x: []string{"foo", "Bar", "BAZ"}, y: []string{"Foo", "BAR", "baz"}, opts: []cmp.Option{ - AcyclicTransformer("", func(s string) string { return strings.ToUpper(s) }), + AcyclicTransformer("", strings.ToUpper), }, wantEqual: true, reason: "equal because of strings.ToUpper; AcyclicTransformer unnecessary, but check this still works", @@ -815,7 +815,7 @@ func TestOptions(t *testing.T) { x: "this is a sentence", y: "this is a sentence", opts: []cmp.Option{ - AcyclicTransformer("", func(s string) []string { return strings.Fields(s) }), + AcyclicTransformer("", strings.Fields), }, wantEqual: true, reason: "equal because acyclic transformer splits on any contiguous whitespace", diff --git a/cmp/report_slices.go b/cmp/report_slices.go index 8cb3265..667a6e3 100644 --- a/cmp/report_slices.go +++ b/cmp/report_slices.go @@ -322,7 +322,7 @@ func coalesceInterveningIdentical(groups []diffStats, windowSize int) []diffStat hadX, hadY := prev.NumRemoved > 0, prev.NumInserted > 0 hasX, hasY := next.NumRemoved > 0, next.NumInserted > 0 if ((hadX || hasX) && (hadY || hasY)) && curr.NumIdentical <= windowSize { - *prev = (*prev).Append(*curr).Append(*next) + *prev = prev.Append(*curr).Append(*next) groups = groups[:len(groups)-1] // Truncate off equal group continue } diff --git a/cmp/report_text.go b/cmp/report_text.go index 0353b50..8b8fcab 100644 --- a/cmp/report_text.go +++ b/cmp/report_text.go @@ -365,7 +365,7 @@ func (s diffStats) String() string { // Pluralize the name (adjusting for some obscure English grammar rules). name := s.Name if sum > 1 { - name = name + "s" + name += "s" if strings.HasSuffix(name, "ys") { name = name[:len(name)-2] + "ies" // e.g., "entrys" => "entries" } -- cgit v1.2.3