aboutsummaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/text/internal/gen/code.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/internal/gen/code.go')
-rw-r--r--vendor/golang.org/x/text/internal/gen/code.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/vendor/golang.org/x/text/internal/gen/code.go b/vendor/golang.org/x/text/internal/gen/code.go
index 2202c9f..d7031b6 100644
--- a/vendor/golang.org/x/text/internal/gen/code.go
+++ b/vendor/golang.org/x/text/internal/gen/code.go
@@ -117,13 +117,7 @@ func (w *CodeWriter) WriteConst(name string, x interface{}) {
switch v.Type().Kind() {
case reflect.String:
- // See golang.org/issue/13145.
- const arbitraryCutoff = 16
- if v.Len() > arbitraryCutoff {
- w.printf("var %s %s = ", name, typeName(x))
- } else {
- w.printf("const %s %s = ", name, typeName(x))
- }
+ w.printf("const %s %s = ", name, typeName(x))
w.WriteString(v.String())
w.printf("\n")
default:
@@ -203,16 +197,27 @@ func (w *CodeWriter) WriteString(s string) {
// When starting on its own line, go fmt indents line 2+ an extra level.
n, max := maxWidth, maxWidth-4
+ // As per https://golang.org/issue/18078, the compiler has trouble
+ // compiling the concatenation of many strings, s0 + s1 + s2 + ... + sN,
+ // for large N. We insert redundant, explicit parentheses to work around
+ // that, lowering the N at any given step: (s0 + s1 + ... + s63) + (s64 +
+ // ... + s127) + etc + (etc + ... + sN).
+ explicitParens, extraComment := len(s) > 128*1024, ""
+ if explicitParens {
+ w.printf(`(`)
+ extraComment = "; the redundant, explicit parens are for https://golang.org/issue/18078"
+ }
+
// Print "" +\n, if a string does not start on its own line.
b := w.buf.Bytes()
if p := len(bytes.TrimRight(b, " \t")); p > 0 && b[p-1] != '\n' {
- w.printf("\"\" + // Size: %d bytes\n", len(s))
+ w.printf("\"\" + // Size: %d bytes%s\n", len(s), extraComment)
n, max = maxWidth, maxWidth
}
w.printf(`"`)
- for sz, p := 0, 0; p < len(s); {
+ for sz, p, nLines := 0, 0, 0; p < len(s); {
var r rune
r, sz = utf8.DecodeRuneInString(s[p:])
out := s[p : p+sz]
@@ -229,6 +234,10 @@ func (w *CodeWriter) WriteString(s string) {
chars = len(out)
}
if n -= chars; n < 0 {
+ nLines++
+ if explicitParens && nLines&63 == 63 {
+ w.printf("\") + (\"")
+ }
w.printf("\" +\n\"")
n = max - len(out)
}
@@ -236,6 +245,9 @@ func (w *CodeWriter) WriteString(s string) {
p += sz
}
w.printf(`"`)
+ if explicitParens {
+ w.printf(`)`)
+ }
}
// WriteSlice writes a slice value.