Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3868

Java struct equals should do identity check before field comparison

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.9.3, 0.10.0
    • 0.10.0
    • Java - Compiler
    • None

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              pho Dustin Pho
              mrettig Mike Rettig
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: