diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rexml/source.rb | 13 |
2 files changed, 13 insertions, 6 deletions
@@ -1,3 +1,9 @@ +Thu Oct 18 16:39:34 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * lib/rexml/source.rb (REXML::SourceFactory::SourceFactory): more + duck typed. better performance on JRuby. + http://headius.blogspot.com/2007/10/another-performance-discovery-rexml.html + Thu Oct 18 09:33:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * range.c (range_first): takes first n element if argument is diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index bc99c0ed6a..659bcdc195 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -7,13 +7,14 @@ module REXML # @param arg Either a String, or an IO # @return a Source, or nil if a bad argument was given def SourceFactory::create_from(arg) - if arg.kind_of? String - Source.new(arg) - elsif arg.respond_to? :read and - arg.respond_to? :readline and - arg.respond_to? :nil? and - arg.respond_to? :eof? + if arg.respond_to? :read and + arg.respond_to? :readline and + arg.respond_to? :nil? and + arg.respond_to? :eof? IOSource.new(arg) + elsif arg.respond_to? :to_str + require 'stringio' + IOSource.new(StringIO.new(arg)) elsif arg.kind_of? Source arg else |