Skip to content

Implement IBufferWriter<char> on ICharTermAttribute/CharTermAttribute and OpenStringBuilder #1315

@NightOwl888

Description

@NightOwl888

Is there an existing issue for this?

  • I have searched the existing issues

Task description

#1293 (comment)

The BCL IBufferWriter<T> interface is purpose-built for allowing arbitrary code to grow and write to a buffer when the source has either a known or unknown buffer length. This allows for scenarios with complex business logic that would be wasteful to repeat if the buffer passed in is not already large enough, without the baggage of System.Text.StringBuilder, which cannot even be converted to a ReadOnlySpan<char> without doing an extra allocation.

IAppendable is an interface from Java that performs a similar operation and IBufferWriter<T> has the potential to eliminate it from the Lucene.NET codebase. However, for now we should limit this addition to CharTermAttribute and the Normalizer2 in ICU4N which will give us a cross-library proof of concept.

The IBufferWriter<T> interface should be inherited directly by ICharTermAttribute, which is a breaking API change. However, due to the limited use cases of IAttribute-derived types, this is unlikely to affect many end users. The implementation of the 3 members will then need to be on the CharTermAttribute class.

The implementation should use the existing growth semantics provided by InternalResizeBuffer. See the Append(ReadOnlySpan<char>) implementation for an example.

See the ArrayBufferWriter and its tests to see an optimized implementation example along with some tests we can use to verify the implementation.

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions