[
https://issues.apache.org/jira/browse/PROTON-1965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16690703#comment-16690703
]
ASF GitHub Bot commented on PROTON-1965:
----------------------------------------
Github user franz1981 commented on a diff in the pull request:
https://github.com/apache/qpid-proton-j/pull/20#discussion_r234421816
--- Diff:
proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
---
@@ -825,33 +825,67 @@ public int hashCode() {
}
@Override
- public boolean equals(Object other) {
- if (this == other) {
+ public boolean equals(Object other)
+ {
+ if (this == other)
+ {
return true;
}
- if (!(other instanceof ReadableBuffer)) {
+ if (!(other instanceof ReadableBuffer))
+ {
return false;
}
- ReadableBuffer buffer = (ReadableBuffer)other;
- if (this.remaining() != buffer.remaining()) {
+ ReadableBuffer buffer = (ReadableBuffer) other;
+ final int remaining = remaining();
+ if (remaining != buffer.remaining())
+ {
return false;
}
+ if (hasArray())
+ {
+ return equals(currentArray, position, remaining, buffer);
+ }
+ else
+ {
+ return equals(this, buffer);
+ }
+ }
- final int currentPos = position();
-
- for (int i = buffer.position(); hasRemaining(); i++) {
- if (!equals(this.get(), buffer.get(i))) {
+ private static boolean equals(byte[] buffer, int start, int length,
ReadableBuffer other)
+ {
+ final int position = other.position();
+ for (int i = 0; i < length; i++)
+ {
+ if (buffer[start + i] != other.get(position + i))
+ {
return false;
}
}
-
- position(currentPos);
-
return true;
}
+ private static boolean equals(ReadableBuffer buffer, ReadableBuffer
other)
+ {
+ final int currentPos = buffer.position();
+ try
+ {
+ for (int i = other.position(); buffer.hasRemaining(); i++)
+ {
+ if (!equals(buffer.get(), other.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ finally
+ {
+ buffer.position(currentPos);
--- End diff --
@tabish121 I have added a reset of the position that wasn't present in the
original code, I hope that's correct
> Optimize CompositeReadableBuffer::equals with single chunk
> ----------------------------------------------------------
>
> Key: PROTON-1965
> URL: https://issues.apache.org/jira/browse/PROTON-1965
> Project: Qpid Proton
> Issue Type: Improvement
> Affects Versions: proton-j-0.30.0
> Reporter: Francesco Nigro
> Priority: Minor
>
> CompositeReadableBuffer::equals with single chunk could be optimized in order
> to
> access directly the single array chunk to speed up memory accesses.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]