[前][次][番号順一覧][スレッド一覧]

ruby-changes:36198

From: nobu <ko1@a...>
Date: Wed, 5 Nov 2014 14:19:23 +0900 (JST)
Subject: [ruby-changes:36198] nobu:r48279 (trunk): cpu_counter.rb: separate implementations

nobu	2014-11-05 14:19:15 +0900 (Wed, 05 Nov 2014)

  New Revision: 48279

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48279

  Log:
    cpu_counter.rb: separate implementations
    
    * lib/rake/cpu_counter.rb (Rake::CpuCounter#count): separate
      Etc.nprocessors implementation, and if is is available other
      utility methods are never used.

  Modified files:
    trunk/lib/rake/cpu_counter.rb
Index: lib/rake/cpu_counter.rb
===================================================================
--- lib/rake/cpu_counter.rb	(revision 48278)
+++ lib/rake/cpu_counter.rb	(revision 48279)
@@ -1,8 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/lib/rake/cpu_counter.rb#L1
-require 'rbconfig'
-
-# TODO: replace with IO.popen using array-style arguments in Rake 11
-require 'open3'
-
 module Rake
 
   # Based on a script at:
@@ -18,6 +13,26 @@ module Rake https://github.com/ruby/ruby/blob/trunk/lib/rake/cpu_counter.rb#L13
       default
     end
 
+    begin
+      require 'etc'
+    rescue LoadError
+    else
+      if Etc.respond_to?(:nprocessors)
+        def count
+          return Etc.nprocessors
+        end
+      end
+    end
+  end
+end
+
+unless Rake::CpuCounter.method_defined?(:count)
+  Rake::CpuCounter.class_eval <<-'end;', __FILE__, __LINE__+1
+    require 'rbconfig'
+
+    # TODO: replace with IO.popen using array-style arguments in Rake 11
+    require 'open3'
+
     def count
       if defined?(Java::Java)
         count_via_java_runtime
@@ -44,18 +59,6 @@ module Rake https://github.com/ruby/ruby/blob/trunk/lib/rake/cpu_counter.rb#L59
       end
     end
 
-    begin
-      require 'etc'
-    rescue LoadError
-    else
-      if Etc.respond_to?(:nprocessors)
-        undef count
-        def count
-          return Etc.nprocessors
-        end
-      end
-    end
-
     def count_via_java_runtime
       Java::Java.lang.Runtime.getRuntime.availableProcessors
     rescue StandardError
@@ -118,5 +121,5 @@ module Rake https://github.com/ruby/ruby/blob/trunk/lib/rake/cpu_counter.rb#L121
         out.eof? ? nil : command
       end
     end
-  end
+  end;
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]