From 845e6ff45a704d1cb0495a31c05f5cb190252a43 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 7 Oct 2007 09:15:26 +0000 Subject: [PATCH] String#to_xs uses the fast_xs extension if available for Builder speedup. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7773 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/base.rb | 1 + activesupport/CHANGELOG | 2 ++ activesupport/Rakefile | 1 + activesupport/lib/active_support.rb | 2 ++ activesupport/lib/active_support/basic_object.rb | 5 ++--- .../active_support/core_ext/array/conversions.rb | 2 ++ .../active_support/core_ext/hash/conversions.rb | 1 + .../lib/active_support/core_ext/string.rb | 1 + .../lib/active_support/core_ext/string/xchar.rb | 10 ++++++++++ activesupport/test/abstract_unit.rb | 16 +++++++++------- 10 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/string/xchar.rb diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 4f5fb7d4be568..61b66add52a90 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -1,4 +1,5 @@ require 'erb' +require 'builder' class ERB module Util diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index ffc88ef6afd10..9bbe395923f0d 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* String#to_xs uses the fast_xs extension if available for Builder speedup. [Jeremy Kemper] + * Introduce BasicObject as Builder::BlankSlate for Ruby 1.9 forward compatibility. [Jeremy Kemper] * Unbundle Builder in favor of a gem dependency. [Jeremy Kemper] diff --git a/activesupport/Rakefile b/activesupport/Rakefile index a27f8dead4e3e..a056caa945c66 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -18,6 +18,7 @@ task :default => :test Rake::TestTask.new { |t| t.pattern = 'test/**/*_test.rb' t.verbose = true + t.warning = true } # Create compressed packages diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 33ed840aa7e04..e7117e22bec6a 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -24,6 +24,8 @@ $:.unshift(File.dirname(__FILE__)) $:.unshift(File.dirname(__FILE__) + "/active_support/vendor") +require 'rubygems' + require 'active_support/basic_object' require 'active_support/inflector' diff --git a/activesupport/lib/active_support/basic_object.rb b/activesupport/lib/active_support/basic_object.rb index 7a3d1a9ed0ff9..1464f9d9b7972 100644 --- a/activesupport/lib/active_support/basic_object.rb +++ b/activesupport/lib/active_support/basic_object.rb @@ -1,6 +1,5 @@ -# Ruby 1.9 introduces BasicObject. Use Builder's BlankSlate before then. +# Ruby 1.9 introduces BasicObject. Use Builder's BlankSlate until then. unless defined? BasicObject - require 'rubygems' - require 'builder' + require 'builder/blankslate' BasicObject = Builder::BlankSlate end diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 8205843a2bd86..89a4499369fe7 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -1,3 +1,5 @@ +require 'builder' + module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 97b4301bdd105..6ac913e5b9ba5 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -2,6 +2,7 @@ require 'xml_simple' require 'cgi' require 'base64' +require 'builder' # Extensions needed for Hash#to_query class Object diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index 724b2af2ee7e2..b3e1b1189aa2c 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -4,6 +4,7 @@ require 'active_support/core_ext/string/starts_ends_with' require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char) require 'active_support/core_ext/string/unicode' +require 'active_support/core_ext/string/xchar' class String #:nodoc: include ActiveSupport::CoreExtensions::String::Access diff --git a/activesupport/lib/active_support/core_ext/string/xchar.rb b/activesupport/lib/active_support/core_ext/string/xchar.rb new file mode 100644 index 0000000000000..d6aa4aa036c3d --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/xchar.rb @@ -0,0 +1,10 @@ +begin + require 'fast_xs' + + class String + alias_method :original_xs, :to_xs if method_defined?(:to_xs) + alias_method :to_xs, :fast_xs + end +rescue LoadError + # fast_xs extension unavailable. +end diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index da157a81c8939..2cfa245bc8b5a 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -5,13 +5,15 @@ require 'active_support' # Wrap tests that use Mocha and skip if unavailable. -def uses_mocha(test_name) - require 'rubygems' - gem 'mocha', '>= 0.5.5' - require 'mocha' - yield -rescue LoadError - $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." +unless defined? uses_mocha + def uses_mocha(test_name) + require 'rubygems' + gem 'mocha', '>= 0.5.5' + require 'mocha' + yield + rescue LoadError + $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." + end end # Show backtraces for deprecated behavior for quicker cleanup.