Skip to content

Commit e1c1722

Browse files
committed
Minor refactoring
1 parent 3b278e2 commit e1c1722

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

deps/rabbit/src/rabbit_amqp_filter_sql.erl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
eval/2,
1919
is_control_char/1]).
2020

21-
%% [filtex-v1.0-wd09 7.1]
21+
%% [Filter-Expressions-v1.0 7.1]
22+
%% https://docs.oasis-open.org/amqp/filtex/v1.0/csd01/filtex-v1.0-csd01.html#_Toc67929316
2223
-define(MAX_EXPRESSION_LENGTH, 4096).
2324
-define(MAX_TOKENS, 200).
2425

@@ -297,13 +298,16 @@ sql_to_list(SQL) ->
297298
error
298299
end.
299300

300-
check_length(String)
301-
when length(String) > ?MAX_EXPRESSION_LENGTH ->
302-
rabbit_log:warning("SQL expression length ~b exceeds maximum length ~b",
303-
[length(String), ?MAX_EXPRESSION_LENGTH]),
304-
error;
305-
check_length(_) ->
306-
ok.
301+
check_length(String) ->
302+
Len = length(String),
303+
case Len =< ?MAX_EXPRESSION_LENGTH of
304+
true ->
305+
ok;
306+
false ->
307+
rabbit_log:warning("SQL expression length ~b exceeds maximum length ~b",
308+
[Len, ?MAX_EXPRESSION_LENGTH]),
309+
error
310+
end.
307311

308312
tokenize(String, SQL) ->
309313
case rabbit_amqp_sql_lexer:string(String) of
@@ -334,12 +338,11 @@ parse(Tokens, SQL) ->
334338
end.
335339

336340
transform_ast(Ast0, SQL) ->
337-
try rabbit_amqp_sql_ast:map(
338-
fun({'like', _Ident, _Pattern, _Escape} = Node) ->
339-
transform_pattern_node(Node);
340-
(Node) ->
341-
Node
342-
end, Ast0) of
341+
try rabbit_amqp_sql_ast:map(fun({'like', _Id, _Pat, _Esc} = Node) ->
342+
transform_pattern_node(Node);
343+
(Node) ->
344+
Node
345+
end, Ast0) of
343346
Ast ->
344347
{ok, Ast}
345348
catch {invalid_pattern, Reason} ->
@@ -357,9 +360,8 @@ has_binary_identifier(Ast) ->
357360
end, Ast).
358361

359362
%% If the Pattern contains no wildcard or a single % wildcard,
360-
%% we will optimise message evaluation by using Erlang pattern matching.
361-
%% Otherwise, we will match with a regex. Even though we compile regexes,
362-
%% they are slower compared to Erlang pattern matching.
363+
%% we will evaluate messages using Erlang pattern matching since
364+
%% that's faster than evaluating compiled regexes.
363365
transform_pattern_node({Op, Ident, Pattern, Escape}) ->
364366
Pat = transform_pattern(Pattern, Escape),
365367
{Op, Ident, {pattern, Pat}}.

0 commit comments

Comments
 (0)