Skip to content

Span: DangerousCreate should avoid argument validation #19670

@ahsonkhan

Description

@ahsonkhan

For Span/ReadOnlySpan DangerousCreate method, should we remove the following test cases to increase performance:

  • SpanTests - DangerousCreateNullObject
  • SpanTests - DangerousCreateBadLength
  • ReadOnlySpanTests - DangerousCreateNullObject
  • ReadOnlySpanTests - DangerousCreateBadLength

It was suggested that the Fast and Slow Span implementations should not do the check/throw on null object or negative lengths to speed up creation of the instance of Span/ReadOnlySpan.

That is, these checks should be removed:

        public static ReadOnlySpan<T> DangerousCreate(object obj, ref T objectData, int length)
        {
            if (obj == null)
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
            if (length < 0)
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);

Should they be removed?

Metadata

Metadata

Assignees

Labels

area-System.MemoryenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions