Skip to content

Commit

Permalink
⚡✅ Update debug output gsub to run in O(n)
Browse files Browse the repository at this point in the history
The same string transform is simple without negative lookahead by
using a block with gsub and checking `$'.empty?`.
  • Loading branch information
nevans committed Apr 28, 2023
1 parent bac5fd7 commit 4816f10
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2443,8 +2443,8 @@ def put_string(str)
if @debug_output_bol
$stderr.print("C: ")
end
$stderr.print(str.gsub(/\n(?!\z)/n, "\nC: "))
if /\r\n\z/n.match(str)
$stderr.print(str.gsub(/\n/n) { $'.empty? ? $& : "\nC: " })
if /\n\z/n.match(str)
@debug_output_bol = true
else
@debug_output_bol = false
Expand Down
3 changes: 0 additions & 3 deletions test/net/imap/test_regexps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class IMAPRegexpsTest < Test::Unit::TestCase
exclude_map: {
Net::IMAP => %i[BodyTypeAttachment BodyTypeExtension], # deprecated
},
exclude: [
/\n(?!\z)/n, # TODO (in Net::IMAP#put_string)
]
).to_h
)

Expand Down

0 comments on commit 4816f10

Please sign in to comment.