big-r81 commented on code in PR #40:
URL: https://github.com/apache/couchdb-config/pull/40#discussion_r945948837
##########
src/config_util.erl:
##########
@@ -72,3 +73,16 @@ fix_path_list(["."|Rest], Acc) ->
fix_path_list(Rest, Acc);
fix_path_list([Dir | Rest], Acc) ->
fix_path_list(Rest, [Dir | Acc]).
+
+% Remove leading and trailing ws from string
+% Implementation used from mochiweb_headers for speed
+% discussion https://github.com/mochi/mochiweb/pull/247
+trim_leading_and_trailing_ws(S) ->
+ trim_and_reverse(trim_and_reverse(S, false), false).
+
+trim_and_reverse([S | Rest], Reversed) when S=:=$ ; S=:=$\n; S=:=$\t ->
+ trim_and_reverse(Rest, Reversed);
+trim_and_reverse(V, false) ->
+ trim_and_reverse(lists:reverse(V), true);
+trim_and_reverse(V, true) ->
+ V.
Review Comment:
Hi, yes we defnitly could. It's not as fast as the solution above. I updated
the gist, which tests the speed of the different functions.
https://gist.github.com/big-r81/62bfc3078257b5e0ba21550fcbe694c7
```
T1 (trim_leading_and_trailing_ws) : 15.104292
T2 (trim_and_reverse) : 0.452117
T3 (trim_leading_and_trailing_ws_2): 0.677198
T4 (string:trim/1): 4.317254
ok
```
So, should we use string:trim?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]