Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Description

Simplifies flag checking patterns that can be combined into single bitwise operations, improving code generation as described in issue #93954.

Patterns simplified:

  • OR checks: (flags & A) != 0 || (flags & B) != 0(flags & (A | B)) != 0
  • AND checks: x.HasFlag(A) && x.HasFlag(B)(x & (A | B)) == (A | B)
  • Has A but not B: (x & A) != 0 && (x & B) == 0(x & (A | B)) == A

Files changed:

  • Uri.cs: Combined CompressPath | ConvertPathSlashes | UnEscapeDotsAndSlashes check; simplified 4 InFact/NotAny combinations
  • XmlSchemaValidator.cs: Combined ProcessInlineSchema | ProcessSchemaLocation check
  • NegotiateAuthenticationPal.ManagedNtlm.cs: Simplified NegotiateSign && NegotiateKeyExchange assertion
  • UpgradeToGeneratedRegexCodeFixer.cs: Simplified IgnoreCase && !CultureInvariant check
  • Number.Parsing.Common.cs: Simplified StateSign && !StateCurrency check
  • Test files: FakeNtlmServer.cs, DynamicRevocationTests.cs, TypeBuilderDefineNestedType.cs

Example:

// Before
if (InFact(Flags.E_PathNotCanonical) && NotAny(Flags.UserEscaped))

// After  
if ((_flags & (Flags.E_PathNotCanonical | Flags.UserEscaped)) == Flags.E_PathNotCanonical)
Original prompt

The checks in

(((syntaxFlags & (UriSyntaxFlags.CompressPath | UriSyntaxFlags.ConvertPathSlashes)) != 0) ||
(syntaxFlags & UriSyntaxFlags.UnEscapeDotsAndSlashes) != 0)))
are testing a pattern along the lines of
if ((flags & (Flags.A | Flags.B)) != 0 || (flags & Flags.C) != 0)
this can be simplified to just
if ((flags & (Flags.A | Flags.B | Flags.C)) != 0

Fix that occurance as well as any other place throughout libraries where flag checks could be combined together


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 31, 2026 01:15
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix combined flag checks in libraries Simplify flag checks throughout libraries Jan 31, 2026
Copilot AI requested a review from MihaZupan January 31, 2026 01:28
@MihaZupan MihaZupan added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Jan 31, 2026
Copilot AI and others added 2 commits January 31, 2026 01:39
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
@MihaZupan
Copy link
Member

@MihuBot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants