You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2015/09/10 02:34:16 UTC
[14/26] couchdb-mango git commit: stash compiled regexs in mochiglobal
stash compiled regexs in mochiglobal
Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/7032bf58
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/7032bf58
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/7032bf58
Branch: refs/heads/master
Commit: 7032bf582ba9483c41ae3e36ad543788852bac2a
Parents: 460fcd4
Author: Tony Sun <to...@cloudant.com>
Authored: Wed Aug 26 01:50:27 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Wed Aug 26 01:50:27 2015 -0700
----------------------------------------------------------------------
src/mango_selector_text.erl | 7 ++-
src/mango_util.erl | 98 ++++++++++++++++++----------------------
2 files changed, 46 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/7032bf58/src/mango_selector_text.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector_text.erl b/src/mango_selector_text.erl
index e61f759..08aa6ee 100644
--- a/src/mango_selector_text.erl
+++ b/src/mango_selector_text.erl
@@ -26,9 +26,7 @@
%% Regex for <<"\\.">>
--define(PERIOD, {re_pattern,0,0,<<69,82,67,80,57,0,0,0,0,0,0,0,2,0,0,0,
-0,0,0,0,46,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,93,0,
-5,27,46,84,0,5,0>>}).
+-define(PERIOD, "\\.").
convert(Object) ->
@@ -181,7 +179,8 @@ convert(Path, {[{Field0, Cond}]}) ->
% an incorrect query since we need [<<"a.b">>]. Without breaking
% our escaping mechanism, we simply revert this first parse_field
% effect and replace instances of "." to "\\.".
- PP1 = [re:replace(P, ?PERIOD, <<"\\\\.">>,
+ MP = mango_util:cached_re(mango_period, ?PERIOD),
+ PP1 = [re:replace(P, MP, <<"\\\\.">>,
[global,{return,binary}]) || P <- PP0],
{PP2, HasInteger} = replace_array_indexes(PP1, [], false),
NewPath = PP2 ++ Path,
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/7032bf58/src/mango_util.erl
----------------------------------------------------------------------
diff --git a/src/mango_util.erl b/src/mango_util.erl
index aa11310..0e71312 100644
--- a/src/mango_util.erl
+++ b/src/mango_util.erl
@@ -40,7 +40,9 @@
join/2,
- parse_field/1
+ parse_field/1,
+
+ cached_re/2
]).
@@ -48,59 +50,33 @@
-include("mango.hrl").
-%% Regex for Floating Point, Hex Floating Point, Nan, and Infinity
-%% Digits = "(\\p{N}+)",
-%% HexDigits = "([0-9a-fA-F]+)",
-%% Exp = "[eE][+-]?" ++ Digits,
-%% FpRegexStr = "[\\x00-\\x20]*" ++ "[+-]?(" ++ "NaN|"
-%% ++ "Infinity|" ++ "((("
-%% ++ Digits
-%% ++ "(\\.)?("
-%% ++ Digits
-%% ++ "?)("
-%% ++ Exp
-%% ++ ")?)|"
-%% ++ "(\\.("
-%% ++ Digits
-%% ++ ")("
-%% ++ Exp
-%% ++ ")?)|"
-%% ++ "(("
-%% ++ "(0[xX]"
-%% ++ HexDigits
-%% ++ "(\\.)?)|"
-%% ++ "(0[xX]"
-%% ++ HexDigits
-%% ++ "?(\\.)"
-%% ++ HexDigits
-%% ++ ")"
-%% ++ ")[pP][+-]?" ++ Digits ++ "))" ++ "[fFdD]?))" ++ "[\\x00-\\x20]*"
--define(NUMSTRING, {re_pattern,25,0,<<69,82,67,80,71,3,0,0,0,0,0,0,1,0,0,0,25,0,
-0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,93,3,19,77,255,255,
-255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,77,0,0,0,0,0,
-40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,94,0,11,0,1,27,78,27,
-97,27,78,83,0,19,27,73,27,110,27,102,27,105,27,110,27,105,27,116,27,121,83,2,
-137,94,2,131,0,2,94,0,145,0,3,94,0,137,0,4,94,0,9,0,5,58,15,2,3,84,0,9,102,94,0,
-7,0,6,27,46,84,0,7,94,0,18,0,7,102,94,0,9,0,8,58,15,2,3,84,0,9,84,0,18,102,94,0,
-84,0,9,77,0,0,0,0,0,0,0,0,32,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,77,
-0,0,0,0,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,94,0,9,0,10,
-58,15,2,3,84,0,9,84,0,84,84,0,137,83,0,121,94,0,115,0,11,27,46,94,0,17,0,12,94,
-0,9,0,13,58,15,2,3,84,0,9,84,0,17,102,94,0,84,0,14,77,0,0,0,0,0,0,0,0,32,0,0,0,
-32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,77,0,0,0,0,0,40,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,94,0,9,0,15,58,15,2,3,84,0,9,84,0,84,84,0,
-115,83,1,79,94,1,73,0,16,94,0,101,0,17,94,0,93,0,18,27,48,77,0,0,0,0,0,0,0,0,0,
-0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,0,39,0,19,77,0,0,0,0,0,0,255,3,
-126,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,84,0,39,102,94,0,7,0,20,
-27,46,84,0,7,84,0,93,83,0,141,94,0,135,0,21,27,48,77,0,0,0,0,0,0,0,0,0,0,0,1,0,
-0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102,94,0,39,0,22,77,0,0,0,0,0,0,255,3,126,
-0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,84,0,39,94,0,7,0,23,27,46,84,
-0,7,94,0,39,0,24,77,0,0,0,0,0,0,255,3,126,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,71,84,0,39,84,0,135,84,0,242,77,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,77,0,0,0,0,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,73,94,0,9,0,25,58,15,2,3,84,0,9,84,1,73,84,2,89,77,0,0,0,0,0,0,0,
-0,80,0,0,0,80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,84,2,131,84,2,167,77,255,
-255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,84,3,19,
-0>>}).
+-define(DIGITS, "(\\p{N}+)").
+-define(HEXDIGITS, "([0-9a-fA-F]+)").
+-define(EXP, "[eE][+-]?" ++ ?DIGITS).
+-define(NUMSTRING,
+"[\\x00-\\x20]*" ++ "[+-]?(" ++ "NaN|"
+ ++ "Infinity|" ++ "((("
+ ++ ?DIGITS
+ ++ "(\\.)?("
+ ++ ?DIGITS
+ ++ "?)("
+ ++ ?EXP
+ ++ ")?)|"
+ ++ "(\\.("
+ ++ ?DIGITS
+ ++ ")("
+ ++ ?EXP
+ ++ ")?)|"
+ ++ "(("
+ ++ "(0[xX]"
+ ++ ?HEXDIGITS
+ ++ "(\\.)?)|"
+ ++ "(0[xX]"
+ ++ ?HEXDIGITS
+ ++ "?(\\.)"
+ ++ ?HEXDIGITS
+ ++ ")"
+ ++ ")[pP][+-]?" ++ ?DIGITS ++ "))" ++ "[fFdD]?))" ++ "[\\x00-\\x20]*").
open_doc(Db, DocId) ->
@@ -373,7 +349,8 @@ join(Sep, [Item | Rest]) ->
is_number_string(Value) when is_binary(Value) ->
is_number_string(binary_to_list(Value));
is_number_string(Value) when is_list(Value)->
- case re:run(Value, ?NUMSTRING) of
+ MP = cached_re(mango_numstring_re, ?NUMSTRING),
+ case re:run(Value, MP) of
nomatch ->
false;
_ ->
@@ -381,6 +358,17 @@ is_number_string(Value) when is_list(Value)->
end.
+cached_re(Name, RE) ->
+ case mochiglobal:get(Name) of
+ undefined ->
+ {ok, MP} = re:compile(RE),
+ ok = mochiglobal:put(Name, MP),
+ MP;
+ MP ->
+ MP
+ end.
+
+
parse_field(Field) ->
case binary:match(Field, <<"\\">>, []) of
nomatch ->