Skip to content

Commit 5203a65

Browse files
committed
Revert "Merge pull request #397 from mame/performance-improvement"
This reverts commit 41207e8, reversing changes made to 86c8448.
1 parent 7ebf6ab commit 5203a65

File tree

3 files changed

+46
-89
lines changed

3 files changed

+46
-89
lines changed

lib/rdoc/parser/c.rb

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -606,46 +606,18 @@ def find_attr_comment var_name, attr_name, read = nil, write = nil
606606
RDoc::Comment.new comment, @top_level
607607
end
608608

609-
##
610-
# Generate a Ruby-method table
611-
612-
def gen_body_table file_content
613-
table = {}
614-
file_content.scan(%r{
615-
((?>/\*.*?\*/\s*)?)
616-
((?:(?:\w+)\s+)?
617-
(?:intern\s+)?VALUE\s+(\w+)
618-
\s*(?:\([^)]*\))(?:[^;]|$))
619-
| ((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+(\w+)\s+(\w+))
620-
| ^\s*\#\s*define\s+(\w+)\s+(\w+)
621-
}xm) do
622-
case
623-
when $1
624-
table[$3] = [:func_def, $1, $2, $~.offset(2)] if !table[$3] || table[$3][0] != :func_def
625-
when $4
626-
table[$6] = [:macro_def, $4, $5, $~.offset(5), $7] if !table[$6] || table[$6][0] == :macro_alias
627-
when $8
628-
table[$8] ||= [:macro_alias, $9]
629-
end
630-
end
631-
table
632-
end
633-
634609
##
635610
# Find the C code corresponding to a Ruby method
636611

637612
def find_body class_name, meth_name, meth_obj, file_content, quiet = false
638-
if file_content
639-
@body_table ||= {}
640-
@body_table[file_content] ||= gen_body_table file_content
641-
type, *args = @body_table[file_content][meth_name]
642-
end
643-
644-
case type
645-
when :func_def
646-
comment = RDoc::Comment.new args[0], @top_level
647-
body = args[1]
648-
offset, = args[2]
613+
case file_content
614+
when %r%((?>/\*.*?\*/\s*)?)
615+
((?:(?:\w+)\s+)?
616+
(?:intern\s+)?VALUE\s+#{meth_name}
617+
\s*(\([^)]*\))([^;]|$))%xm then
618+
comment = RDoc::Comment.new $1, @top_level
619+
body = $2
620+
offset, = $~.offset(2)
649621

650622
comment.remove_private if comment
651623

@@ -674,12 +646,12 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
674646
meth_obj.line = file_content[0, offset].count("\n") + 1
675647

676648
body
677-
when :macro_def
678-
comment = RDoc::Comment.new args[0], @top_level
679-
body = args[1]
680-
offset, = args[2]
649+
when %r%((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))%m then
650+
comment = RDoc::Comment.new $1, @top_level
651+
body = $2
652+
offset = $~.offset(2).first
681653

682-
find_body class_name, args[3], meth_obj, file_content, true
654+
find_body class_name, $3, meth_obj, file_content, true
683655

684656
comment.normalize
685657
find_modifiers comment, meth_obj
@@ -693,11 +665,11 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
693665
meth_obj.line = file_content[0, offset].count("\n") + 1
694666

695667
body
696-
when :macro_alias
668+
when %r%^\s*\#\s*define\s+#{meth_name}\s+(\w+)%m then
697669
# with no comment we hope the aliased definition has it and use it's
698670
# definition
699671

700-
body = find_body(class_name, args[0], meth_obj, file_content, true)
672+
body = find_body(class_name, $1, meth_obj, file_content, true)
701673

702674
return body if body
703675

@@ -792,42 +764,28 @@ def find_class_comment class_name, class_mod
792764
class_mod.add_comment comment, @top_level
793765
end
794766

795-
##
796-
# Generate a const table
797-
798-
def gen_const_table file_content
799-
table = {}
800-
@content.scan(%r{
801-
((?>^\s*/\*.*?\*/\s+))
802-
rb_define_(\w+)\((?:\s*(?:\w+),)?\s*
803-
"(\w+)"\s*,
804-
.*?\)\s*;
805-
| Document-(?:const|global|variable):\s
806-
((?:\w+::)*\w+)
807-
\s*?\n((?>.*?\*/))
808-
}mxi) do
809-
case
810-
when $1 then table[[$2, $3]] = $1
811-
when $4 then table[$4] = "/*\n" + $5
812-
end
813-
end
814-
table
815-
end
816-
817767
##
818768
# Finds a comment matching +type+ and +const_name+ either above the
819769
# comment or in the matching Document- section.
820770

821771
def find_const_comment(type, const_name, class_name = nil)
822-
@const_table ||= {}
823-
@const_table[@content] ||= gen_const_table @content
824-
table = @const_table[@content]
825-
826-
comment =
827-
table[[type, const_name]] ||
828-
(class_name && table[class_name + "::" + const_name]) ||
829-
table[const_name] ||
830-
''
772+
comment = if @content =~ %r%((?>^\s*/\*.*?\*/\s+))
773+
rb_define_#{type}\((?:\s*(\w+),)?\s*
774+
"#{const_name}"\s*,
775+
.*?\)\s*;%xmi then
776+
$1
777+
elsif class_name and
778+
@content =~ %r%Document-(?:const|global|variable):\s
779+
#{class_name}::#{const_name}
780+
\s*?\n((?>.*?\*/))%xm then
781+
"/*\n#{$1}"
782+
elsif @content =~ %r%Document-(?:const|global|variable):
783+
\s#{const_name}
784+
\s*?\n((?>.*?\*/))%xm then
785+
"/*\n#{$1}"
786+
else
787+
''
788+
end
831789

832790
RDoc::Comment.new comment, @top_level
833791
end

lib/rdoc/parser/changelog.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ def create_items items
102102
# Groups +entries+ by date.
103103

104104
def group_entries entries
105-
@time_cache ||= {}
106105
entries.group_by do |title, _|
107106
begin
108-
time = @time_cache[title]
109-
(time || Time.parse(title)).strftime '%Y-%m-%d'
107+
Time.parse(title).strftime '%Y-%m-%d'
110108
rescue NoMethodError, ArgumentError
111109
time, = title.split ' ', 2
112110
Time.parse(time).strftime '%Y-%m-%d'
@@ -130,7 +128,6 @@ def group_entries entries
130128
# 'README.EXT.ja: ditto']]
131129

132130
def parse_entries
133-
@time_cache ||= {}
134131
entries = []
135132
entry_name = nil
136133
entry_body = []
@@ -146,7 +143,6 @@ def parse_entries
146143

147144
begin
148145
time = Time.parse entry_name
149-
@time_cache[entry_name] = time
150146
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
151147
entry_name = nil unless entry_name =~ /#{time.year}/
152148
rescue NoMethodError
@@ -189,7 +185,6 @@ def parse_entries
189185
# Converts the ChangeLog into an RDoc::Markup::Document
190186

191187
def scan
192-
@time_cache = {}
193188
entries = parse_entries
194189
grouped_entries = group_entries entries
195190

lib/rdoc/ruby_lex.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def initialize(content, options)
102102
@exp_line_no = @line_no = 1
103103
@here_readed = []
104104
@readed = []
105-
@current_readed = @readed
106105
@rests = []
107106
@seek = 0
108107

108+
@here_header = false
109109
@indent = 0
110110
@indent_stack = []
111111
@lex_state = :EXPR_BEG
@@ -161,7 +161,7 @@ def get_readed
161161
end
162162

163163
readed = @readed.join("")
164-
@readed.clear
164+
@readed = []
165165
readed
166166
end
167167

@@ -171,9 +171,13 @@ def getc
171171
@rests.push nil unless buf_input
172172
end
173173
c = @rests.shift
174-
@current_readed.push c
174+
if @here_header
175+
@here_readed.push c
176+
else
177+
@readed.push c
178+
end
175179
@seek += 1
176-
if c == "\n".freeze
180+
if c == "\n"
177181
@line_no += 1
178182
@char_no = 0
179183
else
@@ -279,7 +283,7 @@ def initialize_input
279283
@indent_stack = []
280284
@lex_state = :EXPR_BEG
281285
@space_seen = false
282-
@current_readed = @readed
286+
@here_header = false
283287

284288
@continue = false
285289
prompt
@@ -458,8 +462,8 @@ def lex_init()
458462
@indent_stack.pop
459463
end
460464
end
461-
@current_readed = @readed
462-
@here_readed.clear
465+
@here_header = false
466+
@here_readed = []
463467
Token(TkNL)
464468
end
465469

@@ -1017,7 +1021,7 @@ def identify_here_document
10171021
doc = '"'
10181022
end
10191023

1020-
@current_readed = @readed
1024+
@here_header = false
10211025
while l = gets
10221026
l = l.sub(/(:?\r)?\n\z/, "\n")
10231027
if (indent ? l.strip : l.chomp) == quoted
@@ -1034,7 +1038,7 @@ def identify_here_document
10341038
doc << '"'
10351039
end
10361040

1037-
@current_readed = @here_readed
1041+
@here_header = true
10381042
@here_readed.concat reserve
10391043
while ch = reserve.pop
10401044
ungetc ch

0 commit comments

Comments
 (0)