Skip to content

Commit 43ec4ce

Browse files
authored
Merge pull request rails#42099 from jhawthorn/optimize_virtual
Extract and optimize virtual path building
2 parents 739bda1 + 7faa50c commit 43ec4ce

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

actionview/lib/action_view/template/resolver.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ class Path
1515
attr_reader :name, :prefix, :partial, :virtual
1616
alias_method :partial?, :partial
1717

18+
def self.virtual(name, prefix, partial)
19+
if prefix.empty?
20+
"#{partial ? "_" : ""}#{name}"
21+
elsif partial
22+
"#{prefix}/_#{name}"
23+
else
24+
"#{prefix}/#{name}"
25+
end
26+
end
27+
1828
def self.build(name, prefix, partial)
19-
virtual = +""
20-
virtual << "#{prefix}/" unless prefix.empty?
21-
virtual << (partial ? "_#{name}" : name)
22-
new name, prefix, partial, virtual
29+
new name, prefix, partial, virtual(name, prefix, partial)
2330
end
2431

2532
def initialize(name, prefix, partial, virtual)

0 commit comments

Comments
 (0)