commit | a11fcdc3c6a0480f74404d4485ebf68c4e23fb0c | [log] [tgz] |
---|---|---|
author | Todd Wang <toddw@google.com> | Mon Nov 16 15:00:29 2015 -0800 |
committer | Todd Wang <toddw@google.com> | Mon Nov 16 15:00:29 2015 -0800 |
tree | 5f1088c71c33e39966aea73a9ebe9501d46353c1 | |
parent | b9f9d6d0f07ca69a5e68613a8fe2c9ae3b1af905 [diff] |
textutil: Simplify and speedup RuneChunkDecoder, add linewrap. [NOTE: nobody actually uses the RuneChunkDecoder API; it's only used in the LineWriter in the same package] The old RuneChunkDecoder API was unnecessarily complicated and slow. In general returning an interface from an interface method is bad for operations that are called many times, since the returned interface is always represented by a pointer (in Go 1.4+), which commonly means that an allocation must be performed. Added some benchmarks to show the difference. In this case we don't really care about the performance, but it's nice to get a simpler API as well. Also added a simple tool "linewrap", which formats text from stdin into pretty output on stdout, using LineWriter. ns/op old new delta UTF8LineWriter_Sizes_0_Width_0 948244 933565 -1.55% UTF8LineWriter_Sizes_0_Width_10 1002200 980595 -2.16% UTF8LineWriter_Sizes_0_Width_Inf 882431 861149 -2.41% UTF8LineWriter_Sizes_1_Width_0 2327690 1341671 -42.36% UTF8LineWriter_Sizes_1_Width_10 2369511 1397329 -41.03% UTF8LineWriter_Sizes_1_Width_Inf 2248815 1275818 -43.27% UTF8LineWriter_Sizes_1_2_3_Width_0 1717722 1206084 -29.79% UTF8LineWriter_Sizes_1_2_3_Width_10 1765252 1251204 -29.12% UTF8LineWriter_Sizes_1_2_3_Width_Inf 1641235 1123916 -31.52% UTF8ChunkDecoder_Sizes_0 219613 189368 -13.77% UTF8ChunkDecoder_Sizes_1 1428130 552981 -61.28% UTF8ChunkDecoder_Sizes_1_2_3 869106 389633 -55.17% allocs old new delta UTF8LineWriter_Sizes_0_Width_0 15 13 -13.33% UTF8LineWriter_Sizes_0_Width_10 15 13 -13.33% UTF8LineWriter_Sizes_0_Width_Inf 17 15 -11.76% UTF8LineWriter_Sizes_1_Width_0 13314 13 -99.90% UTF8LineWriter_Sizes_1_Width_10 13314 13 -99.90% UTF8LineWriter_Sizes_1_Width_Inf 13316 15 -99.89% UTF8LineWriter_Sizes_1_2_3_Width_0 6665 13 -99.80% UTF8LineWriter_Sizes_1_2_3_Width_10 6665 13 -99.80% UTF8LineWriter_Sizes_1_2_3_Width_Inf 6667 15 -99.78% UTF8ChunkDecoder_Sizes_0 23 21 -8.70% UTF8ChunkDecoder_Sizes_1 13322 21 -99.84% UTF8ChunkDecoder_Sizes_1_2_3 6673 21 -99.69% Change-Id: Ifd649cb884a23397ec54332827aff9b8f457d1d2
This repository contains general purpose libraries used by the Vanadium project. TEST