[
https://issues.apache.org/jira/browse/AVRO-3327?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Martin Tzvetanov Grigorov resolved AVRO-3327.
---------------------------------------------
Fix Version/s: 1.11.1
1.12.0
Assignee: Martin Tzvetanov Grigorov
Resolution: Fixed
> Use Pattern Matching to avoid is check followed by cast
> -------------------------------------------------------
>
> Key: AVRO-3327
> URL: https://issues.apache.org/jira/browse/AVRO-3327
> Project: Apache Avro
> Issue Type: Improvement
> Components: csharp
> Affects Versions: 1.11.1
> Reporter: Kyle Schoonover
> Assignee: Martin Tzvetanov Grigorov
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.11.1, 1.12.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> {code:java}
> return (obj is AvroDecimal) && Equals((AvroDecimal)obj); {code}
> In the current code we are checking obj to see if it is in fact an
> AvroDecimal, then we cast it for the next check (technically creating a new
> variable in memory). Since we have already validated it's value type there
> is no need to cast it.
> Suggested Change:
> {code:java}
> return (obj is AvroDecimal @decimal) && Equals(@decimal); {code}
>
> Pattern Matching Overview: [Pattern matching overview - C# guide | Microsoft
> Docs|https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching]
--
This message was sent by Atlassian Jira
(v8.20.1#820001)