Reduce minimum length for specialize string diffing (#275)
The original threshold of 64 was chosen without much thought.
Lower it to 32 now that we have some concrete examples
that it is aesthetically better.
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
diff --git a/cmp/compare_test.go b/cmp/compare_test.go
index 5f02a82..c7a409d 100644
--- a/cmp/compare_test.go
+++ b/cmp/compare_test.go
@@ -1338,6 +1338,19 @@
x: struct{ X MyBytes }{MyBytes("\xde\xad\xbe\xef")},
y: struct{ X MyBytes }{},
reason: "MyBytes should not be printed as text since it is binary data",
+ }, {
+ label: label + "/ShortJSON",
+ x: `{
+ "id": 1,
+ "foo": true,
+ "bar": true,
+}`,
+ y: `{
+ "id": 1434180,
+ "foo": true,
+ "bar": true,
+}`,
+ reason: "short multiline JSON should prefer triple-quoted string diff as it is more readable",
}}
}
diff --git a/cmp/report_slices.go b/cmp/report_slices.go
index 9809228..68b5c1a 100644
--- a/cmp/report_slices.go
+++ b/cmp/report_slices.go
@@ -80,7 +80,7 @@
}
// Use specialized string diffing for longer slices or strings.
- const minLength = 64
+ const minLength = 32
return vx.Len() >= minLength && vy.Len() >= minLength
}
diff --git a/cmp/testdata/diffs b/cmp/testdata/diffs
index 59afe6d..d207803 100644
--- a/cmp/testdata/diffs
+++ b/cmp/testdata/diffs
@@ -1122,6 +1122,18 @@
+ X: nil,
}
>>> TestDiff/Reporter/NonStringifiedNamedBytes
+<<< TestDiff/Reporter/ShortJSON
+ (
+ """
+ {
+- "id": 1,
++ "id": 1434180,
+ "foo": true,
+ "bar": true,
+ }
+ """
+ )
+>>> TestDiff/Reporter/ShortJSON
<<< TestDiff/EmbeddedStruct/ParentStructA/Inequal
teststructs.ParentStructA{
privateStruct: teststructs.privateStruct{