Browse files

Don't bother spawning a new thread if there's only one item

  • Loading branch information...
1 parent 009e3fa commit c01ea8309c16eb77eeb368452df1dadd1e405532 @sferik committed Dec 18, 2013
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/twitter/util.rb
View
9 lib/twitter/util.rb
@@ -1,9 +1,12 @@
module Twitter
module Util
def self.threaded_map(enumerable)
- enumerable.map { |object|
- Thread.new { yield object }
- }.map(&:value)
+ # Don't bother spawning a new thread if there's only one item
+ if enumerable.count == 1
+ enumerable.map { |object| yield object }
+ else
+ enumerable.map { |object| Thread.new { yield object } }.map(&:value)
+ end
end
end
end

0 comments on commit c01ea83

Please sign in to comment.