提交 2949a4ed 编写于 作者: R robm

8234841: Enhance buffering of byte buffers

Reviewed-by: alanb, ahgross, rhalade, psandoz
上级 7474dea2
...@@ -72,7 +72,6 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private ...@@ -72,7 +72,6 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
public $Type$Buffer slice() { public $Type$Buffer slice() {
int pos = this.position(); int pos = this.position();
int lim = this.limit(); int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0); int rem = (pos <= lim ? lim - pos : 0);
int off = (pos << $LG_BYTES_PER_VALUE$) + offset; int off = (pos << $LG_BYTES_PER_VALUE$) + offset;
assert (off >= 0); assert (off >= 0);
......
...@@ -206,7 +206,6 @@ class Direct$Type$Buffer$RW$$BO$ ...@@ -206,7 +206,6 @@ class Direct$Type$Buffer$RW$$BO$
public $Type$Buffer slice() { public $Type$Buffer slice() {
int pos = this.position(); int pos = this.position();
int lim = this.limit(); int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0); int rem = (pos <= lim ? lim - pos : 0);
int off = (pos << $LG_BYTES_PER_VALUE$); int off = (pos << $LG_BYTES_PER_VALUE$);
assert (off >= 0); assert (off >= 0);
......
...@@ -95,13 +95,15 @@ class Heap$Type$Buffer$RW$ ...@@ -95,13 +95,15 @@ class Heap$Type$Buffer$RW$
} }
public $Type$Buffer slice() { public $Type$Buffer slice() {
int rem = this.remaining(); int pos = this.position();
int lim = this.limit();
int rem = (pos <= lim ? lim - pos : 0);
return new Heap$Type$Buffer$RW$(hb, return new Heap$Type$Buffer$RW$(hb,
-1, -1,
0, 0,
rem, rem,
rem, rem,
this.position() + offset); pos + offset);
} }
public $Type$Buffer duplicate() { public $Type$Buffer duplicate() {
......
...@@ -42,12 +42,15 @@ class StringCharBuffer // package-private ...@@ -42,12 +42,15 @@ class StringCharBuffer // package-private
} }
public CharBuffer slice() { public CharBuffer slice() {
int pos = this.position();
int lim = this.limit();
int rem = (pos <= lim ? lim - pos : 0);
return new StringCharBuffer(str, return new StringCharBuffer(str,
-1, -1,
0, 0,
this.remaining(), rem,
this.remaining(), rem,
offset + this.position()); offset + pos);
} }
private StringCharBuffer(CharSequence s, private StringCharBuffer(CharSequence s,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册