From 812b0d11c2e9a1fe4cc412984f4da359467a2f77 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 12 Oct 2013 20:04:33 +0200 Subject: [PATCH] No need to slice before copy. Part of #1848 --- .../multipart/HttpPostRequestDecoder.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java index 7fc1b52e68..b584cecfa9 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java @@ -538,7 +538,7 @@ public class HttpPostRequestDecoder { if (read == '&') { currentStatus = MultiPartStatus.DISPOSITION; ampersandpos = currentpos - 1; - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = true; } else if (read == HttpConstants.CR) { @@ -548,7 +548,7 @@ public class HttpPostRequestDecoder { if (read == HttpConstants.LF) { currentStatus = MultiPartStatus.PREEPILOGUE; ampersandpos = currentpos - 2; - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = false; } else { @@ -561,7 +561,7 @@ public class HttpPostRequestDecoder { } else if (read == HttpConstants.LF) { currentStatus = MultiPartStatus.PREEPILOGUE; ampersandpos = currentpos - 1; - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = false; } @@ -575,7 +575,7 @@ public class HttpPostRequestDecoder { // special case ampersandpos = currentpos; if (ampersandpos > firstpos) { - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); } else if (!currentAttribute.isCompleted()) { setFinalBuffer(EMPTY_BUFFER); } @@ -586,7 +586,7 @@ public class HttpPostRequestDecoder { if (contRead && currentAttribute != null) { // reset index except if to continue in case of FIELD getStatus if (currentStatus == MultiPartStatus.FIELD) { - currentAttribute.addContent(undecodedChunk.slice(firstpos, currentpos - firstpos).copy(), + currentAttribute.addContent(undecodedChunk.copy(firstpos, currentpos - firstpos), false); firstpos = currentpos; } @@ -659,7 +659,7 @@ public class HttpPostRequestDecoder { if (read == '&') { currentStatus = MultiPartStatus.DISPOSITION; ampersandpos = currentpos - 1; - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = true; } else if (read == HttpConstants.CR) { @@ -670,7 +670,7 @@ public class HttpPostRequestDecoder { currentStatus = MultiPartStatus.PREEPILOGUE; ampersandpos = currentpos - 2; sao.setReadPosition(0); - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = false; break loop; @@ -688,7 +688,7 @@ public class HttpPostRequestDecoder { currentStatus = MultiPartStatus.PREEPILOGUE; ampersandpos = currentpos - 1; sao.setReadPosition(0); - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); firstpos = currentpos; contRead = false; break loop; @@ -705,7 +705,7 @@ public class HttpPostRequestDecoder { // special case ampersandpos = currentpos; if (ampersandpos > firstpos) { - setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos).copy()); + setFinalBuffer(undecodedChunk.copy(firstpos, ampersandpos - firstpos)); } else if (!currentAttribute.isCompleted()) { setFinalBuffer(EMPTY_BUFFER); } @@ -716,7 +716,7 @@ public class HttpPostRequestDecoder { if (contRead && currentAttribute != null) { // reset index except if to continue in case of FIELD getStatus if (currentStatus == MultiPartStatus.FIELD) { - currentAttribute.addContent(undecodedChunk.slice(firstpos, currentpos - firstpos).copy(), + currentAttribute.addContent(undecodedChunk.copy(firstpos, currentpos - firstpos), false); 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) { // found so lastPosition is correct and final try { @@ -1766,7 +1766,7 @@ public class HttpPostRequestDecoder { } } lastPosition = sao.getReadPosition(lastrealpos); - ByteBuf buffer = undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(); + ByteBuf buffer = undecodedChunk.copy(readerIndex, lastPosition - readerIndex); if (found) { // found so lastPosition is correct and final try { @@ -1865,7 +1865,7 @@ public class HttpPostRequestDecoder { // so go back of delimiter size try { currentAttribute.addContent( - undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), true); + undecodedChunk.copy(readerIndex, lastPosition - readerIndex), true); } catch (IOException e) { throw new ErrorDataDecoderException(e); } @@ -1873,7 +1873,7 @@ public class HttpPostRequestDecoder { } else { try { currentAttribute.addContent( - undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), false); + undecodedChunk.copy(readerIndex, lastPosition - readerIndex), false); } catch (IOException e) { throw new ErrorDataDecoderException(e); } @@ -1970,7 +1970,7 @@ public class HttpPostRequestDecoder { // so go back of delimiter size try { currentAttribute.addContent( - undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), true); + undecodedChunk.copy(readerIndex, lastPosition - readerIndex), true); } catch (IOException e) { throw new ErrorDataDecoderException(e); } @@ -1978,7 +1978,7 @@ public class HttpPostRequestDecoder { } else { try { currentAttribute.addContent( - undecodedChunk.slice(readerIndex, lastPosition - readerIndex).copy(), false); + undecodedChunk.copy(readerIndex, lastPosition - readerIndex), false); } catch (IOException e) { throw new ErrorDataDecoderException(e); }