Skip to content

Commit

Permalink
⚡️ Simplify header-fld-name parser
Browse files Browse the repository at this point in the history
This speeds up my benchmarks by ~15-20% over 0.4.3, and by 22-40% over
earlier versions.

NOTE: Previously, Net::IMAP recreated the raw original source string.
Now, it returns the decoded astring value.  Although this is technically
incompatible, it should almost never make a difference: all standard
header field names are valid atoms.

(https://www.iana.org/assignments/message-headers/message-headers.xhtml)
  • Loading branch information
nevans committed Nov 7, 2023
1 parent f27dd4c commit ca76d75
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/net/imap/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1104,10 +1104,9 @@ def header_list
# header-fld-name = astring
#
# NOTE: Previously, Net::IMAP recreated the raw original source string.
# Now, it grabs the raw encoded value using @str and @pos. A future
# version may simply return the decoded astring value. Although that is
# technically incompatible, it should almost never make a difference: all
# standard header field names are valid atoms:
# Now, it returns the decoded astring value. Although this is technically
# incompatible, it should almost never make a difference: all standard
# header field names are valid atoms:
#
# https://www.iana.org/assignments/message-headers/message-headers.xhtml
#
Expand All @@ -1122,12 +1121,7 @@ def header_list
# ftext = %d33-57 / ; Printable US-ASCII
# %d59-126 ; characters not including
# ; ":".
def header_fld_name
assert_no_lookahead
start = @pos
astring
@str[start...@pos - 1]
end
alias header_fld_name astring

# mailbox-data = "FLAGS" SP flag-list / "LIST" SP mailbox-list /
# "LSUB" SP mailbox-list / "SEARCH" *(SP nz-number) /
Expand Down

0 comments on commit ca76d75

Please sign in to comment.