NightOwl888 / ICU4N

International Components for Unicode for .NET
Apache License 2.0
26 stars 7 forks source link

Task: Add ValueStringBuilder as an appendable type to the T4 templates #55

Closed NightOwl888 closed 1 month ago

NightOwl888 commented 11 months ago

We will need the ValueStringBuilder overloads to optimize utility methods and avoid heap allocations in the main business logic. This requires updating the CodeGenerationSettings.xml file to include them and editing the T4 templates to correctly generate the overloads.

Note that ValueStringBuilder is a ref struct, so when passed into methods as a parameter, it must be passed as a ref argument. It is also declared internal, so all methods that are generated with it must also be internal.

Example

        public override IAppendable Normalize(string src, IAppendable dest)
        {
            try
            {
                return dest.Append(src);
            }
            catch (IOException e)
            {
                throw new ICUUncheckedIOException(e);  // Avoid declaring "throws IOException".
            }
        }

For the above method, an overload can be generated as:

        internal override void Normalize(string src, ref ValueStringBuilder dest)
        {
            try
            {
                return dest.Append(src);
            }
            catch (IOException e)
            {
                throw new ICUUncheckedIOException(e);  // Avoid declaring "throws IOException".
            }
        }

It would be best to wait until #40 is done before working on this task.