Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 9962:e5707e56381b
8238920: Better Buffer support
Reviewed-by: alanb, ahgross, rhalade, psandoz, mbalao, andrew
author | bpb |
---|---|
date | Wed, 18 Mar 2020 16:05:15 -0700 |
parents | f08f26ff2669 |
children | 7746a8e93b68 |
files | src/share/classes/java/nio/Buffer.java |
diffstat | 1 files changed, 17 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/nio/Buffer.java Wed Mar 25 16:26:21 2020 -0700 +++ b/src/share/classes/java/nio/Buffer.java Wed Mar 18 16:05:15 2020 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -266,8 +266,8 @@ if ((newLimit > capacity) || (newLimit < 0)) throw new IllegalArgumentException(); limit = newLimit; - if (position > limit) position = limit; - if (mark > limit) mark = -1; + if (position > newLimit) position = newLimit; + if (mark > newLimit) mark = -1; return this; } @@ -488,16 +488,18 @@ * @return The current position value, before it is incremented */ final int nextGetIndex() { // package-private - if (position >= limit) + int p = position; + if (p >= limit) throw new BufferUnderflowException(); - return position++; + position = p + 1; + return p; } final int nextGetIndex(int nb) { // package-private - if (limit - position < nb) + int p = position; + if (limit - p < nb) throw new BufferUnderflowException(); - int p = position; - position += nb; + position = p + nb; return p; } @@ -509,16 +511,18 @@ * @return The current position value, before it is incremented */ final int nextPutIndex() { // package-private - if (position >= limit) + int p = position; + if (p >= limit) throw new BufferOverflowException(); - return position++; + position = p + 1; + return p; } final int nextPutIndex(int nb) { // package-private - if (limit - position < nb) + int p = position; + if (limit - p < nb) throw new BufferOverflowException(); - int p = position; - position += nb; + position = p + nb; return p; }