Skip to content

Commit

Permalink
Cache the result of Time.parse
Browse files Browse the repository at this point in the history
Time.parse is painfully slow.
  • Loading branch information
mame committed Mar 15, 2016
1 parent bd698a4 commit 869202f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rdoc/parser/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def create_items items
# Groups +entries+ by date.

def group_entries entries
@time_cache ||= {}
entries.group_by do |title, _|
begin
Time.parse(title).strftime '%Y-%m-%d'
time = @time_cache[title]
(time || Time.parse(title)).strftime '%Y-%m-%d'
rescue NoMethodError, ArgumentError
time, = title.split ' ', 2
Time.parse(time).strftime '%Y-%m-%d'
Expand All @@ -127,6 +129,7 @@ def group_entries entries
# 'README.EXT.ja: ditto']]

def parse_entries
@time_cache ||= {}
entries = []
entry_name = nil
entry_body = []
Expand All @@ -142,6 +145,7 @@ def parse_entries

begin
time = Time.parse entry_name
@time_cache[entry_name] = time
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
entry_name = nil unless entry_name =~ /#{time.year}/
rescue NoMethodError
Expand Down Expand Up @@ -184,6 +188,7 @@ def parse_entries
# Converts the ChangeLog into an RDoc::Markup::Document

def scan
@time_cache = {}
entries = parse_entries
grouped_entries = group_entries entries

Expand Down

0 comments on commit 869202f

Please sign in to comment.