couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r962886 - /couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl
Date Sat, 10 Jul 2010 16:50:00 GMT
Author: fdmanana
Date: Sat Jul 10 16:50:00 2010
New Revision: 962886

URL: http://svn.apache.org/viewvc?rev=962886&view=rev
Log:
Replaced function code with a more efficient version (one order of magnitude faster):

maybe_add_trailing_slash_2(Url) when is_binary(Url) ->
    maybe_add_trailing_slash_2(?b2l(Url));
maybe_add_trailing_slash_2(Url) ->
    case lists:last(Url) of
    $/ ->
        Url;
    _ ->
        Url ++ "/"
    end.

1> Url_1 = <<"http://test.couchdb.org:5984/somedb">>.
<<"http://test.couchdb.org:5984/somedb">>
2> Url_2 = <<"http://test.couchdb.org:5984/somedb/">>.
<<"http://test.couchdb.org:5984/somedb/">>
3> 
3> timer:tc(re, replace, [Url_1, "[^/]$", "&/", [{return, list}]]).
{50,"http://test.couchdb.org:5984/somedb/"}
4> timer:tc(re, replace, [Url_2, "[^/]$", "&/", [{return, list}]]).
{42,"http://test.couchdb.org:5984/somedb/"}
5>
5> timer:tc(couch_httpd_rep, maybe_add_trailing_slash_2, [Url_1]).
{3,"http://test.couchdb.org:5984/somedb/"}
6> timer:tc(couch_httpd_rep, maybe_add_trailing_slash_2, [Url_2]).
{2,"http://test.couchdb.org:5984/somedb/"}


Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl?rev=962886&r1=962885&r2=962886&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl Sat Jul 10 16:50:00 2010
@@ -44,8 +44,15 @@ handle_req(Req) ->
     send_method_not_allowed(Req, "POST").
 
 
+maybe_add_trailing_slash(Url) when is_binary(Url) ->
+    maybe_add_trailing_slash(?b2l(Url));
 maybe_add_trailing_slash(Url) ->
-    re:replace(Url, "[^/]$", "&/", [{return, list}]).
+    case lists:last(Url) of
+    $/ ->
+        Url;
+    _ ->
+        Url ++ "/"
+    end.
 
 parse_rep_db({Props}) ->
     Url = maybe_add_trailing_slash(couch_util:get_value(<<"url">>, Props)),



Mime
View raw message