Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
993a47b2
Commit
993a47b2
authored
Jul 16, 2015
by
Dave Gynn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up interpolation by consolidating interpolator caches
parent
3def1e1e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
8 deletions
+4
-8
lib/paperclip/interpolations.rb
+4
-8
No files found.
lib/paperclip/interpolations.rb
View file @
993a47b2
...
@@ -21,7 +21,7 @@ module Paperclip
...
@@ -21,7 +21,7 @@ module Paperclip
# Returns a sorted list of all interpolations.
# Returns a sorted list of all interpolations.
def
self
.
all
def
self
.
all
self
.
instance_methods
(
false
).
sort
self
.
instance_methods
(
false
).
sort
!
end
end
# Perform the actual interpolation. Takes the pattern to interpolate
# Perform the actual interpolation. Takes the pattern to interpolate
...
@@ -31,18 +31,14 @@ module Paperclip
...
@@ -31,18 +31,14 @@ module Paperclip
def
self
.
interpolate
pattern
,
*
args
def
self
.
interpolate
pattern
,
*
args
pattern
=
args
.
first
.
instance
.
send
(
pattern
)
if
pattern
.
kind_of?
Symbol
pattern
=
args
.
first
.
instance
.
send
(
pattern
)
if
pattern
.
kind_of?
Symbol
result
=
pattern
.
dup
result
=
pattern
.
dup
interpolators_cache
.
each
do
|
tag
|
interpolators_cache
.
each
do
|
method
,
token
|
result
.
gsub!
(
t
ag_pattern_cache
[
tag
])
{
send
(
tag
,
*
args
)
}
result
.
gsub!
(
t
oken
)
{
send
(
method
,
*
args
)
}
if
result
.
include?
(
token
)
end
end
result
result
end
end
def
self
.
tag_pattern_cache
@tag_pattern_cache
||=
Hash
.
new
{
|
hash
,
key
|
hash
[
key
]
=
":
#{
key
}
"
}
end
def
self
.
interpolators_cache
def
self
.
interpolators_cache
@interpolators_cache
||=
all
.
reverse!
@interpolators_cache
||=
all
.
reverse!
.
map!
{
|
method
|
[
method
,
":
#{
method
}
"
]
}
end
end
def
self
.
plural_cache
def
self
.
plural_cache
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment