Add the SeekAheadOptimize class to enable faster seek of bytes values in HttpPostRequestDecoder

This commit is contained in:
Frédéric Brégier 2012-04-30 12:38:07 +03:00 committed by Trustin Lee
parent e8bc276ddd
commit 759d0633a4

View File

@ -116,18 +116,58 @@ 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 SeekAheadNoBackArray extends Exception {
private static final long serialVersionUID = -630418804938699495L;
}
/**
* This class intends to decrease the CPU in seeking ahead some bytes in
* HttpPostRequestDecoder
*/ */
static void skipControlCharacters(ChannelBuffer buffer) { static class SeekAheadOptimize {
for (;;) { byte[] bytes;
char c = (char) buffer.readUnsignedByte();
if (!Character.isISOControl(c) && !Character.isWhitespace(c)) { int readerIndex;
buffer.readerIndex(buffer.readerIndex() - 1);
break; int pos;
int limit;
ChannelBuffer buffer;
/**
* @param buffer
*/
SeekAheadOptimize(ChannelBuffer buffer)
throws SeekAheadNoBackArray {
if (! buffer.hasArray()) {
throw new SeekAheadNoBackArray();
} }
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;
} }
} }