Skip to content

Commit ebb5f9f

Browse files
committed
Avoid repeatedly calling File.basename in TopLevel
1 parent 3337e5b commit ebb5f9f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/rdoc/code_object/top_level.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ class RDoc::TopLevel < RDoc::Context
1616

1717
attr_accessor :absolute_name
1818

19+
##
20+
# Base name of this file
21+
22+
attr_reader :base_name
23+
24+
##
25+
# Base name of this file without the extension
26+
27+
attr_reader :page_name
28+
1929
##
2030
# All the classes or modules that were declared in
2131
# this file. These are assigned to either +#classes_hash+
@@ -40,6 +50,14 @@ def initialize(absolute_name, relative_name = absolute_name)
4050
@relative_name = relative_name
4151
@parser = nil
4252

53+
if relative_name
54+
@base_name = File.basename(relative_name)
55+
@page_name = @base_name.sub(/\.(rb|rdoc|txt|md)$/i, '')
56+
else
57+
@base_name = nil
58+
@page_name = nil
59+
end
60+
4361
@classes_or_modules = []
4462
end
4563

@@ -105,13 +123,6 @@ def add_to_classes_or_modules(mod)
105123
@classes_or_modules << mod
106124
end
107125

108-
##
109-
# Base name of this file
110-
111-
def base_name
112-
File.basename @relative_name
113-
end
114-
115126
alias name base_name
116127

117128
##
@@ -204,16 +215,6 @@ def object_class
204215
end
205216
end
206217

207-
##
208-
# Base name of this file without the extension
209-
210-
def page_name
211-
basename = File.basename @relative_name
212-
basename =~ /\.(rb|rdoc|txt|md)$/i
213-
214-
$` || basename
215-
end
216-
217218
##
218219
# Path to this file for use with HTML generator output.
219220

0 commit comments

Comments
 (0)