No need to slice before copy. Part of #1848

This commit is contained in:
Norman Maurer 2013-10-12 20:04:33 +02:00
parent 951dcc6c10
commit 812b0d11c2

View File

@ -538,7 +538,7 @@ public class HttpPostRequestDecoder {
if (read == '&') { if (read == '&') {
currentStatus = MultiPartStatus.DISPOSITION; currentStatus = MultiPartStatus.DISPOSITION;
ampersandpos = currentpos - 1; ampersandpos = currentpos - 1;
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = true; contRead = true;
} else if (read == HttpConstants.CR) { } else if (read == HttpConstants.CR) {
@ -548,7 +548,7 @@ public class HttpPostRequestDecoder {
if (read == HttpConstants.LF) { if (read == HttpConstants.LF) {
currentStatus = MultiPartStatus.PREEPILOGUE; currentStatus = MultiPartStatus.PREEPILOGUE;
ampersandpos = currentpos - 2; ampersandpos = currentpos - 2;
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = false; contRead = false;
} else { } else {
@ -561,7 +561,7 @@ public class HttpPostRequestDecoder {
} else if (read == HttpConstants.LF) { } else if (read == HttpConstants.LF) {
currentStatus = MultiPartStatus.PREEPILOGUE; currentStatus = MultiPartStatus.PREEPILOGUE;
ampersandpos = currentpos - 1; ampersandpos = currentpos - 1;
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = false; contRead = false;
} }
@ -575,7 +575,7 @@ public class HttpPostRequestDecoder {
// special case // special case
ampersandpos = currentpos; ampersandpos = currentpos;
if (ampersandpos > firstpos) { if (ampersandpos > firstpos) {
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
} else if (!currentAttribute.isCompleted()) { } else if (!currentAttribute.isCompleted()) {
setFinalBuffer(EMPTY_BUFFER); setFinalBuffer(EMPTY_BUFFER);
} }
@ -586,7 +586,7 @@ public class HttpPostRequestDecoder {
if (contRead && currentAttribute != null) { if (contRead && currentAttribute != null) {
// reset index except if to continue in case of FIELD getStatus // reset index except if to continue in case of FIELD getStatus
if (currentStatus == MultiPartStatus.FIELD) { if (currentStatus == MultiPartStatus.FIELD) {
currentAttribute.addContent(undecodedChunk.slice(firstpos, currentpos - firstpos).copy(), currentAttribute.addContent(undecodedChunk.copy(firstpos, currentpos - firstpos),
false); false);
firstpos = currentpos; firstpos = currentpos;
} }
@ -659,7 +659,7 @@ public class HttpPostRequestDecoder {
if (read == '&') { if (read == '&') {
currentStatus = MultiPartStatus.DISPOSITION; currentStatus = MultiPartStatus.DISPOSITION;
ampersandpos = currentpos - 1; ampersandpos = currentpos - 1;
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = true; contRead = true;
} else if (read == HttpConstants.CR) { } else if (read == HttpConstants.CR) {
@ -670,7 +670,7 @@ public class HttpPostRequestDecoder {
currentStatus = MultiPartStatus.PREEPILOGUE; currentStatus = MultiPartStatus.PREEPILOGUE;
ampersandpos = currentpos - 2; ampersandpos = currentpos - 2;
sao.setReadPosition(0); sao.setReadPosition(0);
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = false; contRead = false;
break loop; break loop;
@ -688,7 +688,7 @@ public class HttpPostRequestDecoder {
currentStatus = MultiPartStatus.PREEPILOGUE; currentStatus = MultiPartStatus.PREEPILOGUE;
ampersandpos = currentpos - 1; ampersandpos = currentpos - 1;
sao.setReadPosition(0); sao.setReadPosition(0);
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
firstpos = currentpos; firstpos = currentpos;
contRead = false; contRead = false;
break loop; break loop;
@ -705,7 +705,7 @@ public class HttpPostRequestDecoder {
// special case // special case
ampersandpos = currentpos; ampersandpos = currentpos;
if (ampersandpos > firstpos) { if (ampersandpos > firstpos) {
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos));
} else if (!currentAttribute.isCompleted()) { } else if (!currentAttribute.isCompleted()) {
setFinalBuffer(EMPTY_BUFFER); setFinalBuffer(EMPTY_BUFFER);
} }
@ -716,7 +716,7 @@ public class HttpPostRequestDecoder {
if (contRead && currentAttribute != null) { if (contRead && currentAttribute != null) {
// reset index except if to continue in case of FIELD getStatus // reset index except if to continue in case of FIELD getStatus
if (currentStatus == MultiPartStatus.FIELD) { if (currentStatus == MultiPartStatus.FIELD) {
currentAttribute.addContent(undecodedChunk.slice(firstpos, currentpos - firstpos).copy(), currentAttribute.addContent(undecodedChunk.copy(firstpos, currentpos - firstpos),
false); false);
firstpos = currentpos; firstpos = currentpos;
} }
@ -1648,7 +1648,7 @@ public class HttpPostRequestDecoder {
} }
} }
} }
ByteBuf buffer = undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(); ByteBuf buffer = undecodedChunk.copy(readerIndex, lastPosition - readerIndex);
if (found) { if (found) {
// found so lastPosition is correct and final // found so lastPosition is correct and final
try { try {
@ -1766,7 +1766,7 @@ public class HttpPostRequestDecoder {
} }
} }
lastPosition = sao.getReadPosition(lastrealpos); lastPosition = sao.getReadPosition(lastrealpos);
ByteBuf buffer = undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(); ByteBuf buffer = undecodedChunk.copy(readerIndex, lastPosition - readerIndex);
if (found) { if (found) {
// found so lastPosition is correct and final // found so lastPosition is correct and final
try { try {
@ -1865,7 +1865,7 @@ public class HttpPostRequestDecoder {
// so go back of delimiter size // so go back of delimiter size
try { try {
currentAttribute.addContent( currentAttribute.addContent(
undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), true); undecodedChunk.copy(readerIndex, lastPosition - readerIndex), true);
} catch (IOException e) { } catch (IOException e) {
throw new ErrorDataDecoderException(e); throw new ErrorDataDecoderException(e);
} }
@ -1873,7 +1873,7 @@ public class HttpPostRequestDecoder {
} else { } else {
try { try {
currentAttribute.addContent( currentAttribute.addContent(
undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), false); undecodedChunk.copy(readerIndex, lastPosition - readerIndex), false);
} catch (IOException e) { } catch (IOException e) {
throw new ErrorDataDecoderException(e); throw new ErrorDataDecoderException(e);
} }
@ -1970,7 +1970,7 @@ public class HttpPostRequestDecoder {
// so go back of delimiter size // so go back of delimiter size
try { try {
currentAttribute.addContent( currentAttribute.addContent(
undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), true); undecodedChunk.copy(readerIndex, lastPosition - readerIndex), true);
} catch (IOException e) { } catch (IOException e) {
throw new ErrorDataDecoderException(e); throw new ErrorDataDecoderException(e);
} }
@ -1978,7 +1978,7 @@ public class HttpPostRequestDecoder {
} else { } else {
try { try {
currentAttribute.addContent( currentAttribute.addContent(
undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), false); undecodedChunk.copy(readerIndex, lastPosition - readerIndex), false);
} catch (IOException e) { } catch (IOException e) {
throw new ErrorDataDecoderException(e); throw new ErrorDataDecoderException(e);
} }