Author: fdmanana
Date: Sun Jul 10 12:18:53 2011
New Revision: 1144846

URL: http://svn.apache.org/viewvc?rev=1144846&view=rev
Log:
Faster required content-type check

string:tokens/2 is more efficient then re:split/3

1> timer:tc(re, split, ["application/json", ";", [{return, list}]]).
{20,["application/json"]}
2> timer:tc(re, split, ["application/json", ";", [{return, list}]]).
{50,["application/json"]}
3> timer:tc(re, split, ["application/json", ";", [{return, list}]]).
{50,["application/json"]}
4> timer:tc(re, split, ["application/json", ";", [{return, list}]]).
{57,["application/json"]}
5> timer:tc(re, split, ["application/json", ";", [{return, list}]]).
{48,["application/json"]}
6>
6> timer:tc(string, tokens, ["application/json", ";"]).
{11,["application/json"]}
7> timer:tc(string, tokens, ["application/json", ";"]).
{11,["application/json"]}
8> timer:tc(string, tokens, ["application/json", ";"]).
{7,["application/json"]}
9> timer:tc(string, tokens, ["application/json", ";"]).
{8,["application/json"]}
10> timer:tc(string, tokens, ["application/json", ";"]).
{11,["application/json"]}
11>
11> timer:tc(re, split, ["application/json; text/plain", ";", [{return, 
list}]]).
{28,["application/json"," text/plain"]}
12> timer:tc(re, split, ["application/json; text/plain", ";", [{return, 
list}]]).
{67,["application/json"," text/plain"]}
13> timer:tc(re, split, ["application/json; text/plain", ";", [{return, 
list}]]).
{66,["application/json"," text/plain"]}
14> timer:tc(re, split, ["application/json; text/plain", ";", [{return, 
list}]]).
{26,["application/json"," text/plain"]}
15> timer:tc(re, split, ["application/json; text/plain", ";", [{return, 
list}]]).
{65,["application/json"," text/plain"]}
16>
16> timer:tc(string, tokens, ["application/json; text/plain", ";"]).
{9,["application/json"," text/plain"]}
17> timer:tc(string, tokens, ["application/json; text/plain", ";"]).
{10,["application/json"," text/plain"]}
18> timer:tc(string, tokens, ["application/json; text/plain", ";"]).
{10,["application/json"," text/plain"]}
19> timer:tc(string, tokens, ["application/json; text/plain", ";"]).
{9,["application/json"," text/plain"]}


Modified:
    couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=1144846&r1=1144845&r2=1144846&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Sun Jul 10 12:18:53 2011
@@ -389,8 +389,7 @@ validate_ctype(Req, Ctype) ->
     undefined ->
         throw({bad_ctype, "Content-Type must be "++Ctype});
     ReqCtype ->
-        % ?LOG_ERROR("Ctype ~p ReqCtype ~p",[Ctype,ReqCtype]),
-        case re:split(ReqCtype, ";", [{return, list}]) of
+        case string:tokens(ReqCtype, ";") of
         [Ctype] -> ok;
         [Ctype, _Rest] -> ok;
         _Else ->


Reply via email to