couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1061403 - /couchdb/trunk/src/couchdb/couch_util.erl
Date Thu, 20 Jan 2011 17:19:29 GMT
Author: fdmanana
Date: Thu Jan 20 17:19:28 2011
New Revision: 1061403

URL: http://svn.apache.org/viewvc?rev=1061403&view=rev
Log:
Avoid so many unnecessary iolist_to_binary calls

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

Modified: couchdb/trunk/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=1061403&r1=1061402&r2=1061403&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_util.erl (original)
+++ couchdb/trunk/src/couchdb/couch_util.erl Thu Jan 20 17:19:28 2011
@@ -272,17 +272,15 @@ should_flush(MemThreshHold) ->
     true -> false end.
 
 encodeBase64Url(Url) ->
-    Url1 = iolist_to_binary(re:replace(base64:encode(Url), "=+$", "")),
-    Url2 = iolist_to_binary(re:replace(Url1, "/", "_", [global])),
-    iolist_to_binary(re:replace(Url2, "\\+", "-", [global])).
+    Url1 = re:replace(base64:encode(Url), ["=+", $$], ""),
+    Url2 = re:replace(Url1, "/", "_", [global]),
+    re:replace(Url2, "\\+", "-", [global, {return, binary}]).
 
 decodeBase64Url(Url64) ->
-    Url1 = re:replace(iolist_to_binary(Url64), "-", "+", [global]),
-    Url2 = iolist_to_binary(
-        re:replace(iolist_to_binary(Url1), "_", "/", [global])
-    ),
-    Padding = ?l2b(lists:duplicate((4 - size(Url2) rem 4) rem 4, $=)),
-    base64:decode(<<Url2/binary, Padding/binary>>).
+    Url1 = re:replace(Url64, "-", "+", [global]),
+    Url2 = re:replace(Url1, "_", "/", [global]),
+    Padding = lists:duplicate((4 - iolist_size(Url2) rem 4) rem 4, $=),
+    base64:decode(iolist_to_binary([Url2, Padding])).
 
 dict_find(Key, Dict, DefaultValue) ->
     case dict:find(Key, Dict) of



Mime
View raw message