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

ruby-changes:22153

From: ayumin <ko1@a...>
Date: Wed, 4 Jan 2012 00:05:30 +0900 (JST)
Subject: [ruby-changes:22153] ayumin:r34202 (trunk): * lib/rexml/parsers/baseparser.rb: rexml BaseParser uses

ayumin	2012-01-04 00:05:20 +0900 (Wed, 04 Jan 2012)

  New Revision: 34202

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

  Log:
    * lib/rexml/parsers/baseparser.rb: rexml BaseParser uses
      instance_eval unnecessarily on listener add.
      patch from Charles Nutter. [Bug #5696] [ruby-core:41437]

  Modified files:
    trunk/ChangeLog
    trunk/lib/rexml/parsers/baseparser.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34201)
+++ ChangeLog	(revision 34202)
@@ -1,3 +1,9 @@
+Tue Jan 03 23:57:37 2012  Ayumu AIZAWA  <ayumu.aizawa@g...>
+
+	* lib/rexml/parsers/baseparser.rb: rexml BaseParser uses
+	  instance_eval unnecessarily on listener add.
+	  patch from Charles Nutter. [Bug #5696] [ruby-core:41437]
+
 Tue Jan 03 20:44:13 2012  Ayumu AIZAWA  <ayumu.aizawa@g...>
 
 	* README: add comment for Git user. patch from Arun Agrawal.
Index: lib/rexml/parsers/baseparser.rb
===================================================================
--- lib/rexml/parsers/baseparser.rb	(revision 34201)
+++ lib/rexml/parsers/baseparser.rb	(revision 34202)
@@ -114,22 +114,10 @@
 
       def initialize( source )
         self.stream = source
+        @listeners = []
       end
 
       def add_listener( listener )
-        if !defined?(@listeners) or !@listeners
-          @listeners = []
-          instance_eval <<-EOL
-            alias :_old_pull :pull
-            def pull
-              event = _old_pull
-              @listeners.each do |listener|
-                listener.receive event
-              end
-              event
-            end
-          EOL
-        end
         @listeners << listener
       end
 
@@ -192,6 +180,14 @@
 
       # Returns the next event.  This is a +PullEvent+ object.
       def pull
+        _pull_inner.tap do |event|
+          @listeners.each do |listener|
+            listener.receive event
+          end
+        end
+      end
+
+      def _pull_inner
         if @closed
           x, @closed = @closed, nil
           return [ :end_element, x ]

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

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