Skip to content

Commit 4816f10

Browse files
committed
⚡✅ Update debug output gsub to run in O(n)
The same string transform is simple without negative lookahead by using a block with gsub and checking `$'.empty?`.
1 parent bac5fd7 commit 4816f10

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

lib/net/imap.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,8 +2443,8 @@ def put_string(str)
24432443
if @debug_output_bol
24442444
$stderr.print("C: ")
24452445
end
2446-
$stderr.print(str.gsub(/\n(?!\z)/n, "\nC: "))
2447-
if /\r\n\z/n.match(str)
2446+
$stderr.print(str.gsub(/\n/n) { $'.empty? ? $& : "\nC: " })
2447+
if /\n\z/n.match(str)
24482448
@debug_output_bol = true
24492449
else
24502450
@debug_output_bol = false

test/net/imap/test_regexps.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class IMAPRegexpsTest < Test::Unit::TestCase
2727
exclude_map: {
2828
Net::IMAP => %i[BodyTypeAttachment BodyTypeExtension], # deprecated
2929
},
30-
exclude: [
31-
/\n(?!\z)/n, # TODO (in Net::IMAP#put_string)
32-
]
3330
).to_h
3431
)
3532

0 commit comments

Comments
 (0)