Skip to content

Commit

Permalink
Fix a Rails perf issue.
Browse files Browse the repository at this point in the history
Closes sass#124.
  • Loading branch information
nex3 committed Aug 21, 2012
1 parent 78c02f9 commit 527e2f4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -3,6 +3,11 @@
* Table of contents
{:toc}

## 3.2.2 (Unreleased)

* Fix a performance issue with `@import` that only appears when
ActiveSupport is loaded.

## 3.2.1 (15 August 2012)

* Fix a buggy interaction with Pow and Capybara that caused `EOFError`s.
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/importers/filesystem.rb
Expand Up @@ -28,7 +28,7 @@ def find(name, options)

# @see Base#mtime
def mtime(name, options)
file, s = find_real_file(@root, name)
file, s = Sass::Util.destructure(find_real_file(@root, name))
File.mtime(file) if file
rescue Errno::ENOENT
nil
Expand Down Expand Up @@ -132,7 +132,7 @@ def split(name)
private

def _find(dir, name, options)
full_filename, syntax = find_real_file(dir, name)
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name))
return unless full_filename && File.readable?(full_filename)

options[:syntax] = syntax
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/plugin/staleness_checker.rb
Expand Up @@ -140,7 +140,7 @@ def mtime(uri, importer)
end

def dependencies(uri, importer)
stored_mtime, dependencies = @dependencies[[uri, importer]]
stored_mtime, dependencies = Sass::Util.destructure(@dependencies[[uri, importer]])

if !stored_mtime || stored_mtime < mtime(uri, importer)
dependencies = compute_dependencies(uri, importer)
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/scss/parser.rb
Expand Up @@ -706,7 +706,7 @@ def placeholder_selector
end

def element_name
ns, name = qualified_name(:allow_star_name)
ns, name = Sass::Util.destructure(qualified_name(:allow_star_name))
return unless ns || name

if name == '*'
Expand Down Expand Up @@ -797,7 +797,7 @@ def pseudo_arg
# could start a pseudo expression like "n+1", or it could start a
# selector like "n|m". In order to handle this, we must regrettably
# backtrack.
expr, sel = nil
expr, sel = nil, nil
pseudo_err = catch_error do
expr = pseudo_expr
next if tok?(/[,)]/)
Expand Down
13 changes: 13 additions & 0 deletions lib/sass/util.rb
Expand Up @@ -467,6 +467,19 @@ def glob(path, &block)
Dir.glob(path, &block)
end

# Prepare a value for a destructuring assignment (e.g. `a, b =
# val`). This works around a performance bug when using
# ActiveSupport, and only needs to be called when `val` is likely
# to be `nil` reasonably often.
#
# See [this bug report](http://redmine.ruby-lang.org/issues/4917).
#
# @param val [Object]
# @return [Object]
def destructure(val)
val || []
end

## Cross-Ruby-Version Compatibility

# Whether or not this is running under Ruby 1.8 or lower.
Expand Down

0 comments on commit 527e2f4

Please sign in to comment.