aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorPatrick Mahoney <pat@polycrystal.org>2012-10-27 14:53:10 -0500
committerPatrick Mahoney <pat@polycrystal.org>2012-10-27 14:53:10 -0500
commit8d0efcc5757a486084c73054202702a2028cba77 (patch)
tree6611842c51166a803eae22d5a1f3df016a87b481 /activesupport
parent2e44dda27ae8df9301b1a83bfaa74708678bfcd4 (diff)
downloadrails-8d0efcc5757a486084c73054202702a2028cba77.tar.gz
rails-8d0efcc5757a486084c73054202702a2028cba77.tar.bz2
rails-8d0efcc5757a486084c73054202702a2028cba77.zip
Replace flow-control exception with explicit test.
It was noticed while profiling 'assets:precompile' in JRuby that exception creation was consuming a large portion of time, and some of that was due to File.atomic_write. Testing first with File.exists? eliminates the need for an exception which should be a perfomrance improvement on both JRuby and MRI. In this case, the stat() isn't even extra overhead, since it is always called.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/file/atomic.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb
index 81beb4e85d..38ea7f8fb3 100644
--- a/activesupport/lib/active_support/core_ext/file/atomic.rb
+++ b/activesupport/lib/active_support/core_ext/file/atomic.rb
@@ -23,10 +23,10 @@ class File
yield temp_file
temp_file.close
- begin
+ if File.exists?(file_name)
# Get original file permissions
old_stat = stat(file_name)
- rescue Errno::ENOENT
+ else
# If not possible, probe which are the default permissions in the
# destination directory.
old_stat = probe_stat_in(dirname(file_name))