From 3afef5f7cc55f68f35cb4161d93cb1e659ba12f0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 7 May 2014 09:40:22 +0200 Subject: [PATCH] Lexer support for JRuby. JRuby now passes all tests. Benchmark wise it completes the big XML benchmark in about 500-600 milliseconds. --- ext/java/org/liboga/xml/Lexer.rl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ext/java/org/liboga/xml/Lexer.rl b/ext/java/org/liboga/xml/Lexer.rl index c92321e..d68bc11 100644 --- a/ext/java/org/liboga/xml/Lexer.rl +++ b/ext/java/org/liboga/xml/Lexer.rl @@ -11,6 +11,7 @@ import org.jruby.RubyModule; import org.jruby.RubyClass; import org.jruby.RubyObject; import org.jruby.RubyString; +import org.jruby.util.ByteList; import org.jruby.anno.JRubyClass; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ThreadContext; @@ -20,6 +21,8 @@ import org.jruby.runtime.builtin.IRubyObject; @JRubyClass(name="Oga::XML::Lexer", parent="Object") public class Lexer extends RubyObject { + private Ruby runtime; + %% write data; public static void load(Ruby runtime) @@ -47,6 +50,8 @@ public class Lexer extends RubyObject public Lexer(Ruby runtime, RubyClass klass) { super(runtime, klass); + + this.runtime = runtime; } @JRubyMethod @@ -64,7 +69,7 @@ public class Lexer extends RubyObject int te = 0; int p = 0; int pe = data.length; - int eof = 0; + int eof = data.length; int top = 0; int[] stack = new int[8]; @@ -77,12 +82,20 @@ public class Lexer extends RubyObject public void callback(String name, byte[] data, Encoding enc, int ts, int te) { + ByteList bytelist = new ByteList(data, ts, te - ts, enc, true); + RubyString value = this.runtime.newString(bytelist); + + ThreadContext context = this.runtime.getCurrentContext(); + + this.callMethod(context, name, value); } public void callback_simple(String name) { + ThreadContext context = this.runtime.getCurrentContext(); + this.callMethod(context, name); } }