[jOOQ/jOOQ#16195] Overall performance improvement in
AbstractNamed.hashCode() specialisations by avoiding Name::append
This commit is contained in:
parent
7147879ba5
commit
f480cd823e
@ -272,7 +272,7 @@ final class QualifiedName extends AbstractName {
|
||||
if (n.name == null)
|
||||
h = 31 * h + 0;
|
||||
else
|
||||
h = 31 * h + n.name.hashCode();
|
||||
h = 31 * h + hashCode0(n);
|
||||
}
|
||||
|
||||
hash = h;
|
||||
@ -280,4 +280,42 @@ final class QualifiedName extends AbstractName {
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int hashCode0(Name n1) {
|
||||
return n1 instanceof UnqualifiedName u ? hashCode0(u) : n1.hashCode();
|
||||
}
|
||||
|
||||
static int hashCode0(UnqualifiedName n1) {
|
||||
return n1.name.hashCode();
|
||||
}
|
||||
|
||||
static int hashCode0(Name n1, Name n2) {
|
||||
int h = 1;
|
||||
|
||||
if (!n1.empty()) h = 31 * h + hashCode0(n1);
|
||||
if (!n2.empty()) h = 31 * h + hashCode0(n2);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
static int hashCode0(Name n1, Name n2, Name n3) {
|
||||
int h = 1;
|
||||
|
||||
if (!n1.empty()) h = 31 * h + hashCode0(n1);
|
||||
if (!n2.empty()) h = 31 * h + hashCode0(n2);
|
||||
if (!n3.empty()) h = 31 * h + hashCode0(n3);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
static int hashCode0(Name n1, Name n2, Name n3, Name n4) {
|
||||
int h = 1;
|
||||
|
||||
if (!n1.empty()) h = 31 * h + hashCode0(n1);
|
||||
if (!n2.empty()) h = 31 * h + hashCode0(n2);
|
||||
if (!n3.empty()) h = 31 * h + hashCode0(n3);
|
||||
if (!n4.empty()) h = 31 * h + hashCode0(n4);
|
||||
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ import static org.jooq.conf.RenderImplicitJoinType.DEFAULT;
|
||||
import static org.jooq.conf.RenderImplicitJoinType.SCALAR_SUBQUERY;
|
||||
import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.DefaultMetaProvider.meta;
|
||||
import static org.jooq.impl.QualifiedName.hashCode0;
|
||||
import static org.jooq.impl.SchemaImpl.DEFAULT_SCHEMA;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_OMIT_CLAUSE_EVENT_EMISSION;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_RENDER_IMPLICIT_JOIN;
|
||||
@ -278,9 +279,11 @@ implements
|
||||
if (getTable() == null)
|
||||
return getUnqualifiedName().hashCode();
|
||||
else
|
||||
return defaultIfNull(getTable().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName()
|
||||
.append(getTable().getUnqualifiedName())
|
||||
.append(getUnqualifiedName()).hashCode();
|
||||
return hashCode0(
|
||||
defaultIfNull(getTable().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName(),
|
||||
getTable().getUnqualifiedName(),
|
||||
getUnqualifiedName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -56,6 +56,7 @@ import static org.jooq.impl.DSL.noCondition;
|
||||
import static org.jooq.impl.DefaultMetaProvider.meta;
|
||||
import static org.jooq.impl.Internal.createPathAlias;
|
||||
import static org.jooq.impl.Keywords.K_TABLE;
|
||||
import static org.jooq.impl.QualifiedName.hashCode0;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.SchemaImpl.DEFAULT_SCHEMA;
|
||||
import static org.jooq.impl.Tools.EMPTY_OBJECT;
|
||||
@ -635,7 +636,7 @@ implements
|
||||
public int hashCode() {
|
||||
|
||||
// [#7172] [#10274] [#14875] Cannot use getQualifiedName() based super implementation yet here
|
||||
return defaultIfNull(getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName().append(getUnqualifiedName()).hashCode();
|
||||
return hashCode0(defaultIfNull(getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName(), getUnqualifiedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static org.jooq.impl.QualifiedName.hashCode0;
|
||||
import static org.jooq.impl.SchemaImpl.DEFAULT_SCHEMA;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_STORE_ASSIGNMENT;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
@ -225,14 +226,18 @@ implements
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (getQualifier() instanceof Table)
|
||||
return defaultIfNull(getQualifier().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName()
|
||||
.append(getQualifier().getUnqualifiedName())
|
||||
.append(getUnqualifiedName()).hashCode();
|
||||
return hashCode0(
|
||||
defaultIfNull(getQualifier().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName(),
|
||||
getQualifier().getUnqualifiedName(),
|
||||
getUnqualifiedName()
|
||||
);
|
||||
else
|
||||
return defaultIfNull(getQualifier().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName()
|
||||
.append(getQualifier().getUnqualifiedName())
|
||||
.append(getUDT().getUnqualifiedName())
|
||||
.append(getUnqualifiedName()).hashCode();
|
||||
return hashCode0(
|
||||
defaultIfNull(getQualifier().getSchema(), DEFAULT_SCHEMA.get()).getQualifiedName(),
|
||||
getQualifier().getUnqualifiedName(),
|
||||
getUDT().getUnqualifiedName(),
|
||||
getUnqualifiedName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user