On Wed, 13 Apr 2022 14:56:12 GMT, XenoAmess <d...@openjdk.java.net> wrote:

>> @jmehrens what about this then?
>> I think it safe now(actually this mechanism is learned from Reader)
>
> XenoAmess has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   moving nr declaration from the beginning of the method to where it's 
> actually used

> Yeah forgot about that part. Thus I guess using soft reference would be a 
> better way to deal with this extra memory use issue. So something like
> 
> ```java
> private SoftReference<byte[]> skipBuffer;
> 
> private byte[] skipBuffer(long remaining) {
>     int size = (int) Math.min(MAX_SKIP_BUFFER_SIZE, remaining);
>     SoftReference<byte[]> ref = this.skipBuffer;
>     byte[] buffer;
>     if (ref == null || (buffer = ref.get()) == null || buffer.length < size) {
>         buffer = new byte[size];
>         this.skipBuffer = new SoftReference(buffer);
>     }
>     return buffer;
> }
> ```
> 
> This should be thread-safe, and we can just call `byte[] skipBuffer = 
> skipBuffer(remaining);`

LGTM

-------------

PR: https://git.openjdk.java.net/jdk/pull/5872

Reply via email to