Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-4520 improve sorting performance #4521

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
hmottestad committed Apr 27, 2023
commit 9b070161e28a6398afe79a1989d0ed6e4108a2c3
Original file line number Diff line number Diff line change
@@ -211,6 +211,7 @@ static class TypedLiteral extends AbstractLiteral {
private final String label;
private final CoreDatatype coreDatatype;
private final IRI datatype;
transient private XMLGregorianCalendar cachedCalendarValue;

TypedLiteral(String label) {
this.label = label;
@@ -264,6 +265,16 @@ public IRI getDatatype() {
public CoreDatatype getCoreDatatype() {
return coreDatatype;
}

@Override
public XMLGregorianCalendar calendarValue() {
XMLGregorianCalendar localCalendar = cachedCalendarValue;
if (localCalendar == null) {
localCalendar = super.calendarValue();
cachedCalendarValue = localCalendar;
}
return localCalendar;
}
}

static class TaggedLiteral extends AbstractLiteral {
Original file line number Diff line number Diff line change
@@ -22,47 +22,37 @@ public interface CoreDatatype {
CoreDatatype NONE = DefaultDatatype.NONE;

static int compare(CoreDatatype left, CoreDatatype right) {
assert left != NONE && right != NONE;
if (left.getClass() == right.getClass()) {
return Integer.compare(left.ordinal(), right.ordinal());
}

if (left.isXSDDatatype() && right.isRDFDatatype()) {
int ret = 1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}
if (left.isXSDDatatype() && right.isGEODatatype()) {
int ret = 1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}

if (left.isRDFDatatype() && right.isXSDDatatype()) {
int ret = -1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}
if (left.isRDFDatatype() && right.isGEODatatype()) {
int ret = 1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}

if (left.isGEODatatype() && right.isXSDDatatype()) {
int ret = -1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}
if (left.isGEODatatype() && right.isRDFDatatype()) {
int ret = -1;
assert left.getIri().toString().compareTo(right.getIri().toString()) == ret;
return ret;
}

assert false;
return left.getIri().toString().compareTo(right.getIri().toString());

int compare;

if (left.isXSDDatatype()) {
if (right.isRDFDatatype() || right.isGEODatatype()) {
compare = 1;
} else {
compare = 0;
}
} else if (left.isRDFDatatype()) {
if (right.isXSDDatatype()) {
compare = -1;
} else if (right.isGEODatatype()) {
compare = 1;
} else {
compare = 0;
}
} else if (left.isGEODatatype()) {
if (right.isXSDDatatype() || right.isRDFDatatype()) {
compare = -1;
} else {
compare = 0;
}
} else {
compare = 0;
}

return compare;
}

int ordinal();
@@ -89,9 +79,6 @@ default Optional<XSD> asXSDDatatype() {
}

default XSD asXSDDatatypeOrNull() {
if (this.getClass() == XSD.class) {
return ((XSD) this);
}
return null;
}

@@ -319,6 +306,11 @@ public String toString() {
return iri.toString();
}

@Override
public final XSD asXSDDatatypeOrNull() {
return this;
}

}

enum RDF implements CoreDatatype {