Fix same optimization than from Branch Master issue #292 to branch 3

This commit is contained in:
Frédéric Brégier 2012-05-02 10:22:43 +03:00
parent 871a26b164
commit faf596f691

View File

@ -116,18 +116,59 @@ final class HttpPostBodyUtil {
private HttpPostBodyUtil() { private HttpPostBodyUtil() {
} }
//Some commons methods between HttpPostRequestDecoder and HttpMessageDecoder
/** /**
* Skip control Characters * Exception when NO Backend Array is found
* @param buffer */
*/ static class SeekAheadNoBackArrayException extends Exception {
static void skipControlCharacters(ChannelBuffer buffer) { private static final long serialVersionUID = -630418804938699495L;
for (;;) { }
char c = (char) buffer.readUnsignedByte();
if (!Character.isISOControl(c) && !Character.isWhitespace(c)) { /**
buffer.readerIndex(buffer.readerIndex() - 1); * This class intends to decrease the CPU in seeking ahead some bytes in
break; * HttpPostRequestDecoder
*/
static class SeekAheadOptimize {
byte[] bytes;
int readerIndex;
int pos;
int limit;
ChannelBuffer buffer;
/**
* @param buffer
*/
SeekAheadOptimize(ChannelBuffer buffer) throws SeekAheadNoBackArrayException {
if (!buffer.hasArray()) {
throw new SeekAheadNoBackArrayException();
} }
this.buffer = buffer;
this.bytes = buffer.array();
this.pos = this.readerIndex = buffer.readerIndex();
this.limit = buffer.writerIndex();
}
/**
*
* @param minus this value will be used as (currentPos - minus) to set
* the current readerIndex in the buffer.
*/
void setReadPosition(int minus) {
pos -= minus;
readerIndex = pos;
buffer.readerIndex(readerIndex);
}
void clear() {
this.buffer = null;
this.bytes = null;
this.limit = 0;
this.pos = 0;
this.readerIndex = 0;
} }
} }