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

ASF GitHub Bot commented on THRIFT-3868:
----------------------------------------

GitHub user dustinpho opened a pull request:

    https://github.com/apache/thrift/pull/1106

    THRIFT-3868 Java struct equals should do identity check before field 
comparison

    https://issues.apache.org/jira/browse/THRIFT-3868

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dustinpho/thrift 
use-identity-check-in-comparison

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/1106.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1106
    
----
commit b115f2fabb79156a917ba4200f1f20af54b4fc45
Author: Dustin Pho <[email protected]>
Date:   2016-10-02T14:56:01Z

    THRIFT-3868 Doing identity check in java struct equals before field 
comparisons

----


> Java struct equals should do identity check before field comparison
> -------------------------------------------------------------------
>
>                 Key: THRIFT-3868
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3868
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler
>    Affects Versions: 0.9.3, 0.10.0
>            Reporter: Mike Rettig
>            Priority: Minor
>
> The identity check is cheap and should be done before comparing fields of a 
> struct. Idiomatic equals methods always include this check especially if the 
> field by field comparison can be expensive. 
> Check to add:
> if(that == this) return true;
> 1864   out << indent() << "public boolean equals(" << tstruct->get_name() << 
> " that) {" << endl;
> 1865   indent_up();
> 1866   out << indent() << "if (that == null)" << endl << indent() << "  
> return false;" << endl;
> INSERT IDENTITY CHECK HERE
> 1867 
> 1868   const vector<t_field*>& members = tstruct->get_members();
> 1869   vector<t_field*>::const_iterator m_iter;
> 1870   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
> 1871     out << endl;
> 1872 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to