Builder on 1.9
Like with REXML, I ported XML Builder to run on Ruby version 1.9. As there is likely to be an extended transition period between 1.8 and 2.0, the design goal was to build a single library that supports both.
Major:
- As Ruby 1.9’s support for regular expressions is fully unicode aware, tr and Regexp are used in place of pack and unpack. Should be a major performance win, especially with big strings.
- no more need for
String.to_xsandFixnum.xchr - move from BlankSlate to BasicObject. As it doesn’t include
::Kernel, BasicObject is much more brutal than BlankSlate. Constants like::Stringmust be explicitly qualified, as do methods like::Kernel.raiseand::Kernel.block_given? - Since the use of
$KCODEproduces warnings on Ruby 1.9, this support has been removed from Builder when running on Ruby 1.9. New default (absent$KCODE) switches from “doesn’t understand utf-8” to “supports utf-8”. This means that there will be fewer cases where non-ASCII characters are replaced with XML numeric character references.
Minor:
- trend is towards replacing
assert_raiseswithassert_raise - instance_methods are no longer an array of strings, instead it is an array of symbols. Replace
instance_methods.include?withmethod_defined?
Uninvestigated/Todo:
. Update: done.Builder::CSSrelies oninstance_eval. BasicObject support for this method is under active discussionwhat is the equivalent to rake/contrib/sshpublisher in Ruby 1.9?. Updated: solved.- how this affects alternative implementations like JRuby and IronRuby
use U+FFFD instead of*to indicate invalid Unicode charactersneed to stop the blankslate (and for now, css) tests from running on 1.9integrating this patch
Sam: In general, you should be able to use the gem just fine on JRuby...and if not, it’s a bug and we’ll fix it. WRT 1.9 features, we plan to start adding them after our 1.1 final release this month, but we already have the regular expression engine done (thanks to Marcin Mielzinsky).
Please feel free to contact me directly with any questions. I want to make sure everything works on JRuby.
Posted by Charles Oliver Nutter at"Next performance fix: Builder::XChar" by Sam Ruby
Chuckle. :-) You might take a look at how I completely eliminated to_xs in my patch for Ruby 1.9. Perhaps similar techniques could be used for JRuby, as the root cause is that 1.8 MRI doesn’t grok Unicode?...Excerpt from Nick Sieger: Next performance fix: Builder::XChar at
Sam, thanks for taking this stuff on. The Ruby XML libraries have been driving me nuts for ages, and it’s good to finally see someone at the wheel who’s detail-oriented and has a serious background with XML.
Posted by MenTaLguY at