unicode/bidi: avoid quadratic behavior in Paragraph.Order and Paragraph.Line

Benchmark after this CL:
BenchmarkOrder/UnmatchedIsolateInitiator/1000-64                     100            181841 ns/op          178736 B/op        454 allocs/op
BenchmarkOrder/UnmatchedIsolateInitiator/10000-64                    100           1558342 ns/op         1987454 B/op        488 allocs/op
BenchmarkOrder/UnmatchedIsolateInitiator/100000-64                   100          13354780 ns/op        21749920 B/op        532 allocs/op
BenchmarkOrder/EuropeanNumber/1000-64                                100            120497 ns/op          132600 B/op         64 allocs/op
BenchmarkOrder/EuropeanNumber/10000-64                               100           1274856 ns/op         1558788 B/op         91 allocs/op
BenchmarkOrder/EuropeanNumber/100000-64                              100           9564126 ns/op        17133078 B/op        126 allocs/op
BenchmarkOrder/EuropeanTerminator/1000-64                            100            140028 ns/op          132600 B/op         64 allocs/op
BenchmarkOrder/EuropeanTerminator/10000-64                           100           1215487 ns/op         1558780 B/op         91 allocs/op
BenchmarkOrder/EuropeanTerminator/100000-64                          100          10475726 ns/op        17133080 B/op        126 allocs/op

Benchmark prior to this CL:
BenchmarkOrder/UnmatchedIsolateInitiator/1000-64                       1           1156230 ns/op          153528 B/op        445 allocs/op
BenchmarkOrder/UnmatchedIsolateInitiator/10000-64                      1          65604486 ns/op         1629880 B/op        472 allocs/op
BenchmarkOrder/UnmatchedIsolateInitiator/100000-64                     1        6378678903 ns/op        17648584 B/op        507 allocs/op
BenchmarkOrder/EuropeanNumber/1000-64                                  1           1583490 ns/op          132616 B/op         65 allocs/op
BenchmarkOrder/EuropeanNumber/10000-64                                 1         142909632 ns/op         1558776 B/op         91 allocs/op
BenchmarkOrder/EuropeanNumber/100000-64                                1        14298169190 ns/op       17133064 B/op        126 allocs/op
BenchmarkOrder/EuropeanTerminator/1000-64                              1            684410 ns/op          132600 B/op         64 allocs/op
BenchmarkOrder/EuropeanTerminator/10000-64                             1          48024880 ns/op         1558792 B/op         92 allocs/op
BenchmarkOrder/EuropeanTerminator/100000-64                            1        4761302841 ns/op        17133176 B/op        127 allocs/op

Fixes golang/go#81587

Change-Id: I4a5c88a97542ad2ee71af88d70d964d96a6a6964
Reviewed-on: https://go-review.googlesource.com/c/text/+/834525
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2 files changed
tree: 0d8ffc503d2a2f20d9f5500786bbfe56d7b1d31c
  1. cases/
  2. cmd/
  3. collate/
  4. currency/
  5. date/
  6. encoding/
  7. feature/
  8. internal/
  9. language/
  10. message/
  11. number/
  12. runes/
  13. search/
  14. secure/
  15. transform/
  16. unicode/
  17. width/
  18. .gitattributes
  19. .gitignore
  20. codereview.cfg
  21. CONTRIBUTING.md
  22. doc.go
  23. gen.go
  24. go.mod
  25. go.sum
  26. LICENSE
  27. PATENTS
  28. README.md
README.md

Go Text

Go Reference

This repository holds supplementary Go packages for text processing, many involving Unicode.

CLDR Versioning

It is important that the Unicode version used in x/text matches the one used by your Go compiler. The x/text repository supports multiple versions of Unicode and will match the version of Unicode to that of the Go compiler. At the moment this is supported for Go compilers from version 1.7.

Contribute

To submit changes to this repository, see http://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/text.

To generate the tables in this repository (except for the encoding tables), run go generate from this directory. By default tables are generated for the Unicode version in core and the CLDR version defined in golang.org/x/text/unicode/cldr.

Running go generate will as a side effect create a DATA subdirectory in this directory, which holds all files that are used as a source for generating the tables. This directory will also serve as a cache.

Testing

Run

go test ./...

from this directory to run all tests. Add the “-tags icu” flag to also run ICU conformance tests (if available). This requires that you have the correct ICU version installed on your system.

TODO:

  • updating unversioned source files.

Generating Tables

To generate the tables in this repository (except for the encoding tables), run go generate from this directory. By default tables are generated for the Unicode version in core and the CLDR version defined in golang.org/x/text/unicode/cldr.

Running go generate will as a side effect create a DATA subdirectory in this directory which holds all files that are used as a source for generating the tables. This directory will also serve as a cache.

Versions

To update a Unicode version run

UNICODE_VERSION=x.x.x go generate

where x.x.x must correspond to a directory in https://www.unicode.org/Public/. If this version is newer than the version in core it will also update the relevant packages there. The idna package in x/net will always be updated.

To update a CLDR version run

CLDR_VERSION=version go generate

where version must correspond to a directory in https://www.unicode.org/Public/cldr/.

Note that the code gets adapted over time to changes in the data and that backwards compatibility is not maintained. So updating to a different version may not work.

The files in DATA/{iana|icu|w3|whatwg} are currently not versioned.

Report Issues

The main issue tracker for the text repository is located at https://go.dev/issues. Prefix your issue with “x/text:” in the subject line, so it is easy to find.