Skip to content

Commit 38d7530

Browse files
committed
⚡️ Simplify and speed up SEARCH response parsing
The `mailbox-data` `SEARCH` response parser was refactored, as part of the work on `CONDSTORE` support. This commit contains only the refactoring, which (coincidentally) brings a significant speed improvement: ``` invalid_search_response_multiple_result_with_trailing_space v0.4.6-2-g3ac9912: 70865.1 i/s 0.4.6: 49505.1 i/s - 1.43x slower invalid_search_response_single_result_with_trailing_space v0.4.6-2-g3ac9912: 74398.0 i/s 0.4.6: 67791.1 i/s - 1.10x slower rfc3501_7.2.5_SEARCH_response_example v0.4.6-2-g3ac9912: 65968.9 i/s 0.4.6: 53490.9 i/s - 1.23x slower search_response_multiple_seq_nums_returned v0.4.6-2-g3ac9912: 62777.4 i/s 0.4.6: 47852.3 i/s - 1.31x slower search_response_single_seq_nums_returned v0.4.6-2-g3ac9912: 79656.5 i/s 0.4.6: 69234.9 i/s - 1.15x slower search_response_with_condstore_modseq v0.4.6-2-g3ac9912: 55376.4 i/s 0.4.6: 39129.0 i/s - 1.42x slower ```
1 parent b4a1915 commit 38d7530

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

lib/net/imap/response_parser.rb

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,34 +1452,15 @@ def acl_data
14521452
# mailbox-data = obsolete-search-response / ...
14531453
# obsolete-search-response = "SEARCH" *(SP nz-number)
14541454
def mailbox_data__search
1455-
token = match(T_ATOM)
1456-
name = token.value.upcase
1457-
token = lookahead
1458-
if token.symbol == T_SPACE
1459-
shift_token
1460-
data = []
1461-
while true
1462-
token = lookahead
1463-
case token.symbol
1464-
when T_CRLF
1465-
break
1466-
when T_SPACE
1467-
shift_token
1468-
when T_NUMBER
1469-
data.push(number)
1470-
when T_LPAR
1471-
# TODO: include the MODSEQ value in a response
1472-
shift_token
1473-
match(T_ATOM)
1474-
match(T_SPACE)
1475-
match(T_NUMBER)
1476-
match(T_RPAR)
1477-
end
1478-
end
1479-
else
1480-
data = []
1455+
name = label_in("SEARCH", "SORT")
1456+
data = []
1457+
while _ = SP? && nz_number? do data << _ end
1458+
if lpar?
1459+
label("MODSEQ"); SP!
1460+
mod_sequence_value
1461+
rpar
14811462
end
1482-
return UntaggedResponse.new(name, data, @str)
1463+
UntaggedResponse.new(name, data, @str)
14831464
end
14841465
alias sort_data mailbox_data__search
14851466

0 commit comments

Comments
 (0)