diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/basic_object.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 22 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/grouping.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | activesupport/lib/active_support/multibyte/generators/generate_tables.rb | 0 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/performance.rb | 4 |
6 files changed, 20 insertions, 25 deletions
diff --git a/activesupport/lib/active_support/basic_object.rb b/activesupport/lib/active_support/basic_object.rb index e06da79d26..1f77209e7f 100644 --- a/activesupport/lib/active_support/basic_object.rb +++ b/activesupport/lib/active_support/basic_object.rb @@ -7,7 +7,7 @@ # barebones base class that emulates Builder::BlankSlate while still relying on # Ruby 1.9's BasicObject in Ruby 1.9. module ActiveSupport - if RUBY_VERSION >= '1.9' + if defined? ::BasicObject class BasicObject < ::BasicObject undef_method :== undef_method :equal? diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 67b0a580ea..cedc1afe7f 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -39,7 +39,7 @@ module ActiveSupport @level = level @buffer = [] @auto_flushing = 1 - @no_block = false + @guard = Mutex.new if log.respond_to?(:write) @log = log @@ -54,19 +54,15 @@ module ActiveSupport end end - def set_non_blocking_io - if !RUBY_PLATFORM.match(/java|mswin/) && !(@log == STDOUT) && @log.respond_to?(:write_nonblock) - @no_block = true - end - end - def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # If a newline is necessary then create a new message ending with a newline. # Ensures that the original message is not mutated. message = "#{message}\n" unless message[-1] == ?\n - buffer << message + @guard.synchronize do + buffer << message + end auto_flush message end @@ -98,11 +94,11 @@ module ActiveSupport end def flush - unless buffer.empty? - if @no_block - @log.write_nonblock(buffer.slice!(0..-1).join) - else - @log.write(buffer.slice!(0..-1).join) + @guard.synchronize do + unless buffer.empty? + old_buffer = @buffer + @buffer = [] + @log.write(old_buffer.join) end end end diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index df37afb053..dd1484f8fa 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -19,7 +19,7 @@ module ActiveSupport #:nodoc: # %w(1 2 3).in_groups_of(2, false) {|g| p g} # ["1", "2"] # ["3"] - def in_groups_of(number, fill_with = nil, &block) + def in_groups_of(number, fill_with = nil) if fill_with == false collection = self else @@ -31,7 +31,7 @@ module ActiveSupport #:nodoc: end if block_given? - collection.each_slice(number, &block) + collection.each_slice(number) { |slice| yield(slice) } else returning [] do |groups| collection.each_slice(number) { |group| groups << group } @@ -87,11 +87,11 @@ module ActiveSupport #:nodoc: # # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]] - def split(value = nil, &block) - block ||= Proc.new { |e| e == value } + def split(value = nil) + using_block = block_given? inject([[]]) do |results, element| - if block.call(element) + if (using_block && yield(element)) || (value == element) results << [] else results.last << element diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index 21636b8af4..23dd96e4df 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -11,10 +11,9 @@ module ActiveSupport def freeze_with_memoizable methods.each do |method| - if m = method.to_s.match(/^_unmemoized_(.*)/) - send(m[1]) - end - end + __send__($1) if method.to_s =~ /^_unmemoized_(.*)/ + end unless frozen? + freeze_without_memoizable end end diff --git a/activesupport/lib/active_support/multibyte/generators/generate_tables.rb b/activesupport/lib/active_support/multibyte/generators/generate_tables.rb index 7f807585c5..7f807585c5 100644..100755 --- a/activesupport/lib/active_support/multibyte/generators/generate_tables.rb +++ b/activesupport/lib/active_support/multibyte/generators/generate_tables.rb diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 71d6f4d9c6..70a7f84023 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -72,13 +72,13 @@ module ActiveSupport protected def run_warmup - 5.times { GC.start } + GC.start time = Metrics::Time.new run_test(time, :benchmark) puts "%s (%s warmup)" % [full_test_name, time.format(time.total)] - 5.times { GC.start } + GC.start end def run_profile(metric) |