Project

General

Profile

Bug #5696

rexml BaseParser uses instance_eval unnecessarily on listener add

Added by headius (Charles Nutter) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:41437]

Description

In add_listener in REXML::BaseParser, there's code to instance eval and replace the old "pull" method with a new one that calls all listeners. I assume this was done to avoid the cost of calling .each on the listeners when there's none registered, but when the list is empty this call is nearly a no-op anyway. The singletonizing effect of instance_eval and the redefinition of #pull, on the other hand, cause a cache flush throughout the system.

I have created a patch that removes the instance_eval, initializes the listeners array unconditionally, and does the event #each unconditionally. It passes all tests, and should perform better because it's not damaging the cache.

https://gist.github.com/1420383

This can be safely backported to any Ruby version and has no visible behavior change.

Associated revisions

Revision 5eac5644
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 34202
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Revision 34202
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Revision 34202
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Revision 34202
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Revision 34202
Added by ayumin (Ayumu AIZAWA) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Revision bd895ab1
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 34204
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

Revision 34204
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

Revision 34204
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

Revision 34204
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

Revision 34204
Added by kou (Kouhei Sutou) over 6 years ago

  • lib/rexml/parsers/baseparser.rb: use private instead of _xxx method name. This is Ruby code not Python code. refs #5696

Revision 68fff388
Added by ayumin (Ayumu AIZAWA) over 6 years ago

merge revision(s) 34202:

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34223 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 6166e9cf
Added by ayumin (Ayumu AIZAWA) over 6 years ago

merge revision(s) 34204:

* lib/rexml/parsers/baseparser.rb: use private instead of _xxx
  method name. This is Ruby code not Python code.
  refs #5696

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 Updated by ayumin (Ayumu AIZAWA) over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34202.
Charles, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/rexml/parsers/baseparser.rb: rexml BaseParser uses instance_eval unnecessarily on listener add. patch from Charles Nutter. [Bug #5696]

Also available in: Atom PDF