Permalink
Browse files

HttpHeaders.getMediaType optimization

  • Loading branch information...
patriot1burke committed Jan 26, 2014
1 parent 63049e3 commit b0574283caf164047110dd22b8d42d8eef14b8b6
@@ -54,10 +54,10 @@ public void testUri() throws Exception
@Test
public void testCleartext() throws Exception
{
- final int WARMUP = 10;
- final int INTERATIONS = 100;
- //final int WARMUP = 1000;
- //final int INTERATIONS = 1000000;
+ //final int WARMUP = 10;
+ //final int INTERATIONS = 100;
+ final int WARMUP = 1000;
+ final int INTERATIONS = 1000000;
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.start();
@@ -113,12 +113,19 @@ public int getLength()
return Integer.parseInt(obj);
}
+ // because header string map is mutable, we only cache the parsed media type
+ // and still do hash lookup
+ private String cachedMediaTypeString;
+ private MediaType cachedMediaType;
@Override
public MediaType getMediaType()
{
String obj = requestHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
if (obj == null) return null;
- return MediaType.valueOf(obj);
+ if (obj == cachedMediaTypeString) return cachedMediaType;
+ cachedMediaTypeString = obj;
+ cachedMediaType = MediaType.valueOf(obj);
+ return cachedMediaType;
}
@Override

0 comments on commit b057428

Please sign in to comment.