Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡✅ Update more regexps to run in linear time #147

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bin/check-regexps
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# See also: test/net/imap/regexp_collector.rb
# See also: test/net/imap/test_regexps.rb

def traverse(m=Object, s=Set.new, &b)
m.constants(false).map{m.const_get _1 rescue nil}.select{_1 in Module}.each do
next if s.include?(_1); s << _1
b and b[_1]
traverse(_1, s, &b)
end
end

def collect_regexps = ObjectSpace
.each_object(Regexp)
.reject{Regexp.linear_time? _1}

2.times{traverse}
before = collect_regexps

$LOAD_PATH.unshift "./lib"
require 'net/imap'
2.times{traverse}
traverse(Net::IMAP) { puts _1.name }
after = collect_regexps - before
p before: before.count, count: after.count, after:;
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
14 changes: 1 addition & 13 deletions lib/net/imap/stringprep/saslprep_tables.rb

Large diffs are not rendered by default.

Loading