Skip to content

Remove boxed null guards from generated logarithmic conversions - #227

Merged
matt-edmondson merged 2 commits into
mainfrom
copilot/fix-logarithmic-conversions-null-check
Sep 13, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
copilot/fix-logarithmic-conversions-null-check

Conversation

Copilot AI commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

LogarithmicScalesGenerator was still emitting ArgumentNullException.ThrowIfNull(linear) for linear inputs that are now readonly record struct quantities. That null check is unreachable and forces boxing on every conversion call in the generated logarithmic APIs.

  • Generator emission

    • Removed the null-guard emission from LogarithmicScalesGenerator for From* logarithmic conversion methods.
  • Regenerated logarithmic outputs

    • Regenerated affected files so each From* conversion no longer includes the boxed null check:
      • Cents, Decibels (both FromGain and FromPowerRatio), DirectionalityIndex, PH, Semitones, SoundIntensityLevel, SoundPowerLevel, SoundPressureLevel.
  • Allocation regression guard

    • Extended QuantityValueTypeTests to assert zero allocation for a logarithmic conversion path (Decibels.FromGain), closing the coverage gap that allowed this drift.
public static Decibels<T> FromGain(Gain<T> linear)
{
    double linearValue = double.CreateChecked(linear.Value);
    return new(T.CreateChecked(20.0 * Math.Log10(linearValue)));
}

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix null check for value type parameters in logarithmic conversions Remove boxed null guards from generated logarithmic conversions Sep 13, 2026
@matt-edmondson
matt-edmondson marked this pull request as ready for review September 13, 2026 13:04
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit be25259 into main Sep 13, 2026
13 checks passed
@matt-edmondson
matt-edmondson deleted the copilot/fix-logarithmic-conversions-null-check branch September 13, 2026 23:28
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.

Generated logarithmic conversions still null-check a parameter that is now a value type, boxing on every call

2 participants