提交 e97a7d78 编写于 作者: B bpb

8238920: Better Buffer support

Reviewed-by: alanb, ahgross, rhalade, psandoz
上级 bb6d667a
/* /*
* Copyright (c) 2000, 2016, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -345,8 +345,8 @@ public abstract class Buffer { ...@@ -345,8 +345,8 @@ public abstract class Buffer {
if (newLimit > capacity | newLimit < 0) if (newLimit > capacity | newLimit < 0)
throw createLimitException(newLimit); throw createLimitException(newLimit);
limit = newLimit; limit = newLimit;
if (position > limit) position = limit; if (position > newLimit) position = newLimit;
if (mark > limit) mark = -1; if (mark > newLimit) mark = -1;
return this; return this;
} }
...@@ -637,16 +637,18 @@ public abstract class Buffer { ...@@ -637,16 +637,18 @@ public abstract class Buffer {
* @return The current position value, before it is incremented * @return The current position value, before it is incremented
*/ */
final int nextGetIndex() { // package-private final int nextGetIndex() { // package-private
if (position >= limit) int p = position;
if (p >= limit)
throw new BufferUnderflowException(); throw new BufferUnderflowException();
return position++; position = p + 1;
return p;
} }
final int nextGetIndex(int nb) { // package-private final int nextGetIndex(int nb) { // package-private
if (limit - position < nb)
throw new BufferUnderflowException();
int p = position; int p = position;
position += nb; if (limit - p < nb)
throw new BufferUnderflowException();
position = p + nb;
return p; return p;
} }
...@@ -658,16 +660,18 @@ public abstract class Buffer { ...@@ -658,16 +660,18 @@ public abstract class Buffer {
* @return The current position value, before it is incremented * @return The current position value, before it is incremented
*/ */
final int nextPutIndex() { // package-private final int nextPutIndex() { // package-private
if (position >= limit) int p = position;
if (p >= limit)
throw new BufferOverflowException(); throw new BufferOverflowException();
return position++; position = p + 1;
return p;
} }
final int nextPutIndex(int nb) { // package-private final int nextPutIndex(int nb) { // package-private
if (limit - position < nb)
throw new BufferOverflowException();
int p = position; int p = position;
position += nb; if (limit - p < nb)
throw new BufferOverflowException();
position = p + nb;
return p; return p;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册