Repository: dotnet/aspnetcore
File: src/Http/Headers/src/SetCookieHeaderValue.cs (C#)

Code before:
                }

                itemLength = HttpRuleParser.GetNumberLength(input, offset, allowDecimal: false);
                if (itemLength == 0)
                {
                    return 0;
                }

                var numberString = input.Subsegment(offset, itemLength);
                long maxAge;
                if (!HeaderUtilities.TryParseNonNegativeInt64(numberString, out maxAge))
                {
                    // Invalid expiration date, abort
                    return 0;
                }

                if (isNegative)
                {
                    maxAge = -maxAge;
                }

                // Check if maxAge would cause TimeSpan.FromSeconds to overflow
                // TimeSpan.MaxValue.TotalSeconds is approximately 922337203685.4775
                const long MaxTimeSpanSeconds = 922337203685L;
                const long MinTimeSpanSeconds = -922337203685L;
                if (maxAge > MaxTimeSpanSeconds || maxAge < MinTimeSpanSeconds)
                {
                    // MaxAge value would overflow TimeSpan, abort
                    return 0;
                }

                result.MaxAge = TimeSpan.FromSeconds(maxAge);
                offset += itemLength;
            }
            // domain-av = "Domain=" domain-value
            // domain-value = <subdomain> ; defined in [RFC1034], Section 3.5, as enhanced by [RFC1123], Section 2.1
            else if (StringSegment.Equals(token, DomainToken, StringComparison.OrdinalIgnoreCase))
            {
                // = (no spaces)
                if (!ReadEqualsSign(input, ref offset))
                {
                    return 0;
                }
                // We don't do any detailed validation on the domain.
                result.Domain = ReadToSemicolonOrEnd(input, ref offset);
            }
            // path-av = "Path=" path-value
            // path-value = <any CHAR except CTLs or ";">
            else if (StringSegment.Equals(token, PathToken, StringComparison.OrdinalIgnoreCase))
            {
                // = (no spaces)

Review comment (suggestion):
```suggestion
                if (maxAge is > MaxTimeSpanSeconds or < MinTimeSpanSeconds)
```
Once https://github.com/dotnet/roslyn/issues/60534 lands, we get a free optimization.

Code after:
                }

                itemLength = HttpRuleParser.GetNumberLength(input, offset, allowDecimal: false);
                if (itemLength == 0)
                {
                    return 0;
                }

                var numberString = input.Subsegment(offset, itemLength);
                long maxAge;
                if (!HeaderUtilities.TryParseNonNegativeInt64(numberString, out maxAge))
                {
                    // Invalid expiration date, abort
                    return 0;
                }

                if (isNegative)
                {
                    maxAge = -maxAge;
                }

                // Check if maxAge would cause TimeSpan.FromSeconds to overflow
                // TimeSpan.MaxValue.TotalSeconds is approximately 922337203685.4775
                const long MaxTimeSpanSeconds = 922337203685L;
                const long MinTimeSpanSeconds = -922337203685L;
                if (maxAge is > MaxTimeSpanSeconds or < MinTimeSpanSeconds)
                {
                    // MaxAge value would overflow TimeSpan, abort
                    return 0;
                }

                result.MaxAge = TimeSpan.FromSeconds(maxAge);
                offset += itemLength;
            }
            // domain-av = "Domain=" domain-value
            // domain-value = <subdomain> ; defined in [RFC1034], Section 3.5, as enhanced by [RFC1123], Section 2.1
            else if (StringSegment.Equals(token, DomainToken, StringComparison.OrdinalIgnoreCase))
            {
                // = (no spaces)
                if (!ReadEqualsSign(input, ref offset))
                {
                    return 0;
                }
                // We don't do any detailed validation on the domain.
                result.Domain = ReadToSemicolonOrEnd(input, ref offset);
            }
            // path-av = "Path=" path-value
            // path-value = <any CHAR except CTLs or ";">
            else if (StringSegment.Equals(token, PathToken, StringComparison.OrdinalIgnoreCase))
            {
                // = (no spaces)