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


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to