Make UnsafeArray.AsReadOnly a pure method. This prevents a defensive copy when the instance is readonly
What is the current behaviour?
AsReadonly() is not marked readonly even though it will never mutate the instance. This causes a defensive copy when the instance is readonly referenced (readonly field, in, ref readonly, etc...)
What is the new behaviour?
UnsafeArray.AsReadOnly is marked as readonly indicating to the runtime that it's safe to call this method without creating a defensive copy.
Make
UnsafeArray.AsReadOnly
a pure method. This prevents a defensive copy when the instance isreadonly
What is the current behaviour?
AsReadonly()
is not markedreadonly
even though it will never mutate the instance. This causes a defensive copy when the instance is readonly referenced (readonly
field,in
,ref readonly
, etc...)What is the new behaviour?
UnsafeArray.AsReadOnly
is marked asreadonly
indicating to the runtime that it's safe to call this method without creating a defensive copy.What issues does this resolve?
What PRs does this depend on?
Does this introduce a breaking change?