You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2022/01/30 20:23:00 UTC

[jira] [Commented] (AVRO-3327) Use Pattern Matching to avoid is check followed by cast

    [ https://issues.apache.org/jira/browse/AVRO-3327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17484437#comment-17484437 ] 

ASF subversion and git services commented on AVRO-3327:
-------------------------------------------------------

Commit 2af5d7e0116d53ca706b6e5a5f3b45e7d317ef7d in avro's branch refs/heads/master from Kyle Schoonover
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=2af5d7e ]

AVRO-3327 Implemented pattern matching on Equals check (#1478)

Co-authored-by: Kyle T. Schoonover <Ky...@nordstrom.com>

> 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
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  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)