The current replace.RegexpTransformer offloads buffering to the calling code. It does this by repeatedly returning transform.ErrShortSrc until enough data is available. Even though this technically conforms to the documentation/contract, it fails when used with transform.Chain due to its internal (undocumented) 2kb buffering limit #5 golang/go#49117.
The replace.Chain was added as an alternative to transform.Chain. However, each call to Chain allocates 8kb for each underlying transform.Reader. I've opened a proposal to add a transform.Reader.Reset method, but the author of x/text is unresponsive.
We can avoid all these problems by doing the buffering ourselves.
The current
replace.RegexpTransformeroffloads buffering to the calling code. It does this by repeatedly returningtransform.ErrShortSrcuntil enough data is available. Even though this technically conforms to the documentation/contract, it fails when used withtransform.Chaindue to its internal (undocumented) 2kb buffering limit #5 golang/go#49117.The replace.Chain was added as an alternative to
transform.Chain. However, each call toChainallocates 8kb for each underlyingtransform.Reader. I've opened a proposal to add atransform.Reader.Resetmethod, but the author ofx/textis unresponsive.We can avoid all these problems by doing the buffering ourselves.