This is an automated email from the ASF dual-hosted git repository. jermy pushed a commit to branch checkArgument-avoid-boxing in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit b98636b261107b14cedc49640afe8a36c9169696 Author: Jermy Li <je...@apache.org> AuthorDate: Sun Aug 31 00:24:35 2025 +0800 Query: E.checkArgument avoid boxing long Change-Id: I6e08bd07b7c20c4025ed2a4fc91aaa3cbbd059e0 --- .../org/apache/hugegraph/backend/query/Query.java | 65 +++++++++++++++------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java index 3a024283f..1816bff23 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java @@ -180,7 +180,9 @@ public class Query implements Cloneable { } public void offset(long offset) { - E.checkArgument(offset >= 0L, "Invalid offset %s", offset); + if (offset < 0L) { + E.checkArgument(false, "Invalid offset %s", offset); + } this.offset = offset; } @@ -202,7 +204,9 @@ public class Query implements Cloneable { } public long goOffset(long offset) { - E.checkArgument(offset >= 0L, "Invalid offset value: %s", offset); + if (offset < 0L) { + E.checkArgument(false, "Invalid offset value: %s", offset); + } if (this.originQuery != null) { this.goParentOffset(offset); } @@ -250,9 +254,11 @@ public class Query implements Cloneable { } else if (fromIndex > 0L) { this.goOffset(fromIndex); } - E.checkArgument(fromIndex <= Integer.MAX_VALUE, - "Offset must be <= 0x7fffffff, but got '%s'", - fromIndex); + if (fromIndex > Integer.MAX_VALUE) { + E.checkArgument(false, + "Offset must be <= 0x7fffffff, but got '%s'", + fromIndex); + } if (fromIndex >= elems.size()) { return ImmutableSet.of(); @@ -287,17 +293,27 @@ public class Query implements Cloneable { public long limit() { if (this.capacity != NO_CAPACITY) { - E.checkArgument(this.limit == Query.NO_LIMIT || - this.limit <= this.capacity, - "Invalid limit %s, must be <= capacity(%s)", - this.limit, this.capacity); + if (this.limit == NO_LIMIT) { + /* + * TODO: may need to return this.capacity here. + * In most cases, capacity == DEFAULT_CAPACITY, then limit() + * will return NO_LIMIT, thus rely on Query.checkCapacity() + * to check in the next step. + */ + } + if (this.limit != NO_LIMIT && this.limit > this.capacity) { + E.checkArgument(false, + "Invalid limit %s, must be <= capacity(%s)", + this.limit, this.capacity); + } } return this.limit; } public void limit(long limit) { - E.checkArgument(limit >= 0L || limit == NO_LIMIT, - "Invalid limit %s", limit); + if (limit != NO_LIMIT && limit < 0L) { + E.checkArgument(false, "Invalid limit %s", limit); + } this.limit = limit; } @@ -337,8 +353,9 @@ public class Query implements Cloneable { } else { assert end < Query.NO_LIMIT; } - E.checkArgument(end >= start, - "Invalid range: [%s, %s)", start, end); + if (end < start) { + E.checkArgument(false, "Invalid range: [%s, %s)", start, end); + } this.limit(end - start); } else { // Keep the origin limit @@ -349,11 +366,15 @@ public class Query implements Cloneable { public String page() { if (this.page != null) { - E.checkState(this.limit() != 0L, - "Can't set limit=0 when using paging"); - E.checkState(this.offset() == 0L, - "Can't set offset when using paging, but got '%s'", - this.offset()); + if (this.limit() == 0L) { + E.checkState(false, + "Can't set limit=0 when using paging"); + } + if (this.offset() != 0L) { + E.checkState(false, + "Can't set offset when using paging, but got '%s'", + this.offset()); + } } return this.page; } @@ -409,7 +430,7 @@ public class Query implements Cloneable { public void checkCapacity(long count) throws LimitExceedException { // Throw LimitExceedException if reach capacity - if (this.capacity != Query.NO_CAPACITY && count > this.capacity) { + if (this.capacity != NO_CAPACITY && count > this.capacity) { final int MAX_CHARS = 256; String query = this.toString(); if (query.length() > MAX_CHARS) { @@ -426,8 +447,10 @@ public class Query implements Cloneable { } public Aggregate aggregateNotNull() { - E.checkArgument(this.aggregate != null, - "The aggregate must be set for number query"); + if (this.aggregate == null) { + E.checkArgument(false, + "The aggregate must be set for number query"); + } return this.aggregate; }