Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERFORMANCE: J2N.Text.StringBuilderExtensions: Optimizations #63

Merged
merged 9 commits into from
Dec 26, 2023

Conversation

NightOwl888
Copy link
Owner

@NightOwl888 NightOwl888 commented Dec 26, 2023

New APIs:

namespace J2N.Text
{
    public static class StringBuilderExtensions
    {
        public static StringBuilder Append(this StringBuilder text, ReadOnlySpan<char> charSequence);
        public static StringBuilder Insert(this StringBuilder text, int index, ReadOnlySpan<char> charSequence);
        public static StringBuilder InsertCodePoint(this StringBuilder text, int index, int codePoint);
    }
}

Optimized APIs:

  • Append()
  • AppendCodePoint()
  • CompareToOrdinal()
  • IndexOf()
  • Insert()
  • LastIndexOf()
  • Replace()
  • Reverse()

This also fixes several bugs in ValueStringBuilderArrayPoolIndexer and fixes #58.

These optimizations take advantage of ArrayPool, ValueStringBuilderArrayPoolIndexer, and ValueStringBuilderChunkIndexer to provide faster indexing through the StringBuilder class.

…rloads. Added ReadOnlySpan<char> overload of Append() for older .NET TFMs. Fixed bug in logic of CopyTo() method.
…rloads. Added ReadOnlySpan<char> overload of Insert() for older .NET TFMs. Added tests for Insert() overloads.
…InsertCodePoint() method + tests. While InsertCodePoint didn't exist in Java, it is a common case in ICU4N.
…inal to use value indexers to wrap StringBuilders for faster indexing through the chars using ValueStringBuilderChunkIndexer and ValueStringBuilderArrayPoolIndexer, where supported.
…d LastIndexOf() overloads for Ordinal and OrdinalIgnoreCase using ValueStringBuilderChunkIndexer and ValueStringArrayPoolIndexer, when supported. Slightly optimized other StringComparison options. Added tests for other StringComparison options.
…thod using ValueStringBuilderChunkIndexer(), where supported.
…s with calculations for chunk length and chunk count.
…thod using ValueStringBuilderChunkIndexer and ValueStringBuilderArrayPoolIndexer, where supported. Swapped implementation with that from Apache Harmony (with renamed variables). Fixes #58.
@NightOwl888 NightOwl888 merged commit f39edb8 into main Dec 26, 2023
20 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: StringBuilderExtensions.Reverse() has issue with reversing surrogates
1 participant