Remove excess allocations in Uri.ReCreateParts by MihaZupan · Pull Request #34864 · dotnet/runtime (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack to avoid code analysis from preventing us passing the noEscape span as a parameter with

CS8352 Cannot use local 'noEscape' in this context because it may expose referenced variables outside of their declaration scope
and
CS8350 This combination of arguments to 'UriHelper.EscapeStringToBuilder(ReadOnlySpan<char>, ref ValueStringBuilder, ReadOnlySpan<bool>, bool)' is disallowed because it may expose variables referenced by parameter 'noEscape' outside of their declaration scope

Is this still legal from the runtime's perspective? Can it be avoided (without duplicating EscapeToBuilder by inlining it into this method)?
@stephentoub @jkotas