Reduce the cost of throwing a SeekAheadNoBackArrayException
This commit is contained in:
parent
f799c9f215
commit
d6cedb008b
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Shared Static object between HttpMessageDecoder, HttpPostRequestDecoder and HttpPostRequestEncoder
|
||||
*/
|
||||
@ -120,7 +120,19 @@ final class HttpPostBodyUtil {
|
||||
* Exception when NO Backend Array is found
|
||||
*/
|
||||
static class SeekAheadNoBackArrayException extends Exception {
|
||||
|
||||
static final SeekAheadNoBackArrayException INSTANCE = new SeekAheadNoBackArrayException();
|
||||
|
||||
private static final long serialVersionUID = -630418804938699495L;
|
||||
|
||||
private SeekAheadNoBackArrayException() {
|
||||
// Hide
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,12 +156,12 @@ final class HttpPostBodyUtil {
|
||||
SeekAheadOptimize(ChannelBuffer buffer)
|
||||
throws SeekAheadNoBackArrayException {
|
||||
if (! buffer.hasArray()) {
|
||||
throw new SeekAheadNoBackArrayException();
|
||||
throw SeekAheadNoBackArrayException.INSTANCE;
|
||||
}
|
||||
this.buffer = buffer;
|
||||
this.bytes = buffer.array();
|
||||
this.pos = this.readerIndex = buffer.readerIndex();
|
||||
this.limit = buffer.writerIndex();
|
||||
bytes = buffer.array();
|
||||
pos = readerIndex = buffer.readerIndex();
|
||||
limit = buffer.writerIndex();
|
||||
}
|
||||
/**
|
||||
*
|
||||
@ -163,11 +175,11 @@ final class HttpPostBodyUtil {
|
||||
}
|
||||
|
||||
void clear() {
|
||||
this.buffer = null;
|
||||
this.bytes = null;
|
||||
this.limit = 0;
|
||||
this.pos = 0;
|
||||
this.readerIndex = 0;
|
||||
buffer = null;
|
||||
bytes = null;
|
||||
limit = 0;
|
||||
pos = 0;
|
||||
readerIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user