Mike Rettig created THRIFT-3868:
-----------------------------------
Summary: 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)