You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Namgyu Kim (JIRA)" <ji...@apache.org> on 2018/09/05 17:32:00 UTC
[jira] [Created] (LUCENE-8487) Code Optimizations in FieldType
Namgyu Kim created LUCENE-8487:
----------------------------------
Summary: Code Optimizations in FieldType
Key: LUCENE-8487
URL: https://issues.apache.org/jira/browse/LUCENE-8487
Project: Lucene - Core
Issue Type: Improvement
Components: core/other
Reporter: Namgyu Kim
1) Delete unnecessary _if statement_.
{code:java}
// 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);
}
}
...
}{code}
In this code, we can see that the following _if statement_ is unnecessary.
{code:java}
if (dimensionCount != 0) {
throw new IllegalArgumentException("when dimensionNumBytes is 0, dimensionCount must 0; got " + dimensionCount);
}{code}
Because it is a condition that is already processed in the upper _if statement_
(if dimensionCount == 0)
So I made the following code.
{code:java}
// 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);
}
...
}
{code}
2) Simplify _if statement_
{code:java}
// 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;
}
{code}
The final _if statement_ can be simplified.
{code:java}
// 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;
}{code}
But I worry that change will hinder readability.
For that reason, if it is not good, I will not reflect it in the patch.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org