From 6145afcbf8492e862a9efe7f611a994a00f1a4e7 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 2 Nov 2017 23:30:03 +0300 Subject: [PATCH] Fix compact() operation on NIO buffers --- .../java/org/teavm/classlib/java/nio/TByteBufferImpl.java | 4 ++-- .../java/org/teavm/classlib/java/nio/TCharBufferImpl.java | 4 ++-- .../java/org/teavm/classlib/java/nio/TDoubleBufferImpl.java | 4 ++-- .../java/org/teavm/classlib/java/nio/TFloatBufferImpl.java | 4 ++-- .../main/java/org/teavm/classlib/java/nio/TIntBufferImpl.java | 4 ++-- .../java/org/teavm/classlib/java/nio/TLongBufferImpl.java | 4 ++-- .../java/org/teavm/classlib/java/nio/TShortBufferImpl.java | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java index c13778738..cd7589c03 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java @@ -90,15 +90,15 @@ class TByteBufferImpl extends TByteBuffer { if (readOnly) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int dst = start; int src = start + position; for (int i = 0; i < sz; ++i) { array[dst++] = array[src++]; } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferImpl.java index 95ffeced1..948bda31b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferImpl.java @@ -82,14 +82,14 @@ abstract class TCharBufferImpl extends TCharBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putChar(i, getChar(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBufferImpl.java index c5d4e244e..75326dde8 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBufferImpl.java @@ -82,14 +82,14 @@ abstract class TDoubleBufferImpl extends TDoubleBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putElement(i, getElement(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferImpl.java index 932909232..ea5701700 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferImpl.java @@ -82,14 +82,14 @@ abstract class TFloatBufferImpl extends TFloatBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putElement(i, getElement(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferImpl.java index 25407926c..95d060e98 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferImpl.java @@ -82,14 +82,14 @@ abstract class TIntBufferImpl extends TIntBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putElement(i, getElement(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferImpl.java index 2a8adde70..d9600d0a9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferImpl.java @@ -82,14 +82,14 @@ abstract class TLongBufferImpl extends TLongBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putElement(i, getElement(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this; diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferImpl.java b/classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferImpl.java index b6766b329..6dcea668b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferImpl.java @@ -82,14 +82,14 @@ abstract class TShortBufferImpl extends TShortBuffer { if (isReadOnly()) { throw new TReadOnlyBufferException(); } + int sz = remaining(); if (position > 0) { - int sz = remaining(); int src = position; for (int i = 0; i < sz; ++i) { putElement(i, getElement(src++)); } - position = sz; } + position = sz; limit = capacity; mark = -1; return this;