Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-8487

Code Optimizations in FieldType

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Patch Available
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core/other
    • Labels:
    • Lucene Fields:
      New

      Description

      1) Delete unnecessary if statement.

      // Line 281 method
      public void setDimensions(int dimensionCount, int dimensionNumBytes) {
        ...
        if (dimensionCount == 0) {
          if (dimensionNumBytes != 0) {
            throw new IllegalArgumentException("when dimensionCount is 0, dimensionNumBytes must 0; got " + dimensionNumBytes);
          }
        } else if (dimensionNumBytes == 0) {
          if (dimensionCount != 0) {
            throw new IllegalArgumentException("when dimensionNumBytes is 0, dimensionCount must 0; got " + dimensionCount);
          }
        }
        ...
      }

      In this code, we can see that the following if statement is unnecessary.

      if (dimensionCount != 0) {
        throw new IllegalArgumentException("when dimensionNumBytes is 0, dimensionCount must 0; got " + dimensionCount);
      }

      Because it is a condition that is already processed in the upper if statement
      (if dimensionCount == 0)

      So I made the following code.

      // Line 281 method
      public void setDimensions(int dimensionCount, int dimensionNumBytes) {
        ...
        if (dimensionCount == 0) {
          if (dimensionNumBytes != 0) {
            throw new IllegalArgumentException("when dimensionCount is 0, dimensionNumBytes must 0; got " + dimensionNumBytes);
          }
        } else if (dimensionNumBytes == 0) {
          throw new IllegalArgumentException("when dimensionNumBytes is 0, dimensionCount must 0; got " + dimensionCount);
        }
        ...
      }
      

      2) Simplify if statement

      // Line 417 method
      public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        ...
        if (storeTermVectors != other.storeTermVectors) return false;
        if (stored != other.stored) return false;
        if (tokenized != other.tokenized) return false;
        return true;
      }
      

      The final if statement can be simplified.

      // Line 417 method
      public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        ...
        if (storeTermVectors != other.storeTermVectors) return false;
        if (stored != other.stored) return false;
        return tokenized == other.tokenized;
      }

      But I worry that change will hinder readability.
      For that reason, if it is not good, I will not reflect it in the patch.

        Attachments

        1. LUCENE-8487.patch
          2 kB
          Namgyu Kim

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              danmuzi Namgyu Kim
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: