minor optimisations

This commit is contained in:
Greg Wilkins 2015-05-22 22:53:01 +10:00
parent cc40282a7d
commit b2e8d2cd04
3 changed files with 19 additions and 12 deletions

View File

@ -738,7 +738,7 @@ public class HttpParser
throw new BadMessageException(HttpStatus.BAD_REQUEST_400,"Unknown Version");
// Should we try to cache header fields?
if (_connectionFields==null && _version.getVersion()>=HttpVersion.HTTP_1_1.getVersion())
if (_connectionFields==null && _version.getVersion()>=HttpVersion.HTTP_1_1.getVersion() && _handler.getHeaderCacheSize()>0)
{
int header_cache = _handler.getHeaderCacheSize();
_connectionFields=new ArrayTernaryTrie<>(header_cache);

View File

@ -63,6 +63,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ShutdownThread;
import org.eclipse.jetty.util.thread.SpinLock;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
@ -87,8 +88,10 @@ public class Server extends HandlerWrapper implements Attributes
private boolean _dumpBeforeStop=false;
private RequestLog _requestLog;
private final SpinLock _dateLock = new SpinLock();
private volatile DateField _dateField;
/* ------------------------------------------------------------ */
public Server()
{
@ -309,7 +312,7 @@ public class Server extends HandlerWrapper implements Attributes
if (df==null || df._seconds!=seconds)
{
synchronized (this) // Trade some contention for less garbage
try(SpinLock.Lock lock = _dateLock.lock())
{
df = _dateField;
if (df==null || df._seconds!=seconds)

View File

@ -313,9 +313,11 @@ public class ArrayTernaryTrie<V> extends AbstractTrie<V>
private V getBest(int t,String s,int offset,int len)
{
int node=t;
loop: for(int i=0; i<len; i++)
int end=offset+len;
loop: while(offset<end)
{
char c=s.charAt(offset+i);
char c=s.charAt(offset++);
len--;
if(isCaseInsensitive() && c<128)
c=StringUtil.lowercases[c];
@ -335,9 +337,9 @@ public class ArrayTernaryTrie<V> extends AbstractTrie<V>
if (_key[t]!=null)
{
node=t;
V best=getBest(t,s,offset+i+1,len-i-1);
if (best!=null)
return best;
V better=getBest(t,s,offset,len);
if (better!=null)
return better;
}
break;
}
@ -364,9 +366,11 @@ public class ArrayTernaryTrie<V> extends AbstractTrie<V>
private V getBest(int t,byte[] b, int offset, int len)
{
int node=t;
loop: for(int i=0; i<len; i++)
int end=offset+len;
loop: while(offset<end)
{
byte c=(byte)(b[offset+i]&0x7f);
byte c=(byte)(b[offset++]&0x7f);
len--;
if(isCaseInsensitive())
c=(byte)StringUtil.lowercases[c];
@ -386,9 +390,9 @@ public class ArrayTernaryTrie<V> extends AbstractTrie<V>
if (_key[t]!=null)
{
node=t;
V best=getBest(t,b,offset+i+1,len-i-1);
if (best!=null)
return best;
V better=getBest(t,b,offset,len);
if (better!=null)
return better;
}
break;
}