.NET 8 added support for `AddRange` using the `ReadOnlySpan<T>` data structure. This can significantly improve the performance of `RepeatedField<T>` when adding multiple elements and can avoid the potential need to create extra arrays when using spans.
Here is the code that was added to .NET to support `AddRange` on `List<T>`: 85f6d2d944/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/CollectionExtensions.cs (L85-L103)
In the current implementation of `RepeatedField<T>`, the `AddRange` method only operates on `IEnumerable<T>`. Unfortunately, this means that the callers using `Span<T>` have to copy the content of the span to an array or to some other `IEnumerbale<T>` before calling `AddRange`. This is an expensive operation and can be avoided by adding support for `AddRange` that takes a `ReadOnlySpan<T>` directly.
In this proposal, `AddRange` is added as an extension method instead of directly adding it to `RepeatedField<T>` because we want to avoid ambiguity between `RepeatedField<T>.AddRange(IEnumerbale<T>)` and `RepeatedField<T>.AddRange(Span<T>)` for types such as `T[]`. This is the same exact approach taken by .NET runtime itself.
Closes#19115
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/19115 from prezaei:pedramr/repeated-field-extensions 8d0ac6a0c3
PiperOrigin-RevId: 700357702
Comparing against empty string will first do a reference comparison, then value comparison.
Whitespace changes are caused by `trim_trailing_whitespace = true` in `.editorconfig`
Closes#18934
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/18934 from Henr1k80:main 7467044f8e
PiperOrigin-RevId: 700355679
Also added a test to verify that no uninitialized access happens in NumExtensions.
Creation `Extension()` does zero initialization. Illustration: https://gcc.godbolt.org/z/37j8hrb9T
PiperOrigin-RevId: 698094874
We introduce hpb::ExtensionRegistry::generated_registry. In the future, Parse calls will default to this being the default registry, while still being able to supply their own (if needed).
PiperOrigin-RevId: 697690765