diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-17 11:39:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-09-17 11:50:58 -0700 |
commit | 636624fbf2952e1fd46b95c9199048b3d6647870 (patch) | |
tree | 210087b6b73f5538a5f2265eb679592bfc18956c | |
parent | b5dd1b659987bb6117c0f1657e66dc395cfbed5e (diff) | |
download | rails-636624fbf2952e1fd46b95c9199048b3d6647870.tar.gz rails-636624fbf2952e1fd46b95c9199048b3d6647870.tar.bz2 rails-636624fbf2952e1fd46b95c9199048b3d6647870.zip |
making nokogiri to hash less clever, more fast O_o
[#2243 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
-rw-r--r-- | activesupport/lib/active_support/xml_mini/nokogiri.rb | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 3b2c6a96d9..17bacd8441 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -18,7 +18,7 @@ module ActiveSupport {} else data.ungetc(char) - doc = Nokogiri::XML(data) + doc = Nokogiri::XML(data) { |cfg| cfg.noblanks } raise doc.errors.first if doc.errors.length > 0 doc.to_hash end @@ -39,33 +39,25 @@ module ActiveSupport # hash:: # Hash to merge the converted element into. def to_hash(hash = {}) - hash[name] ||= attributes_as_hash + attributes = attributes_as_hash + if hash[name] + hash[name] = [hash[name]].flatten + hash[name] << attributes + else + hash[name] ||= attributes + end - walker = lambda { |memo, parent, child, callback| - next if child.blank? && 'file' != parent['type'] + children.each { |child| + next if child.blank? && 'file' != self['type'] if child.text? || child.cdata? - (memo[CONTENT_ROOT] ||= '') << child.content + (attributes[CONTENT_ROOT] ||= '') << child.content next end - name = child.name - - child_hash = child.attributes_as_hash - if memo[name] - memo[name] = [memo[name]].flatten - memo[name] << child_hash - else - memo[name] = child_hash - end - - # Recursively walk children - child.children.each { |c| - callback.call(child_hash, child, c, callback) - } + child.to_hash attributes } - children.each { |c| walker.call(hash[name], self, c, walker) } hash end |