From 46709adcd30159ef84cc003bfda610a71cba0225 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Sat, 5 Oct 2019 16:05:35 -0500 Subject: [PATCH] Eliminate callback objects and indirection altogether. There's only ever one implementation of these, so just call them directly. --- ext/puma_http11/http11_parser.java.rl | 50 ++---- ext/puma_http11/org/jruby/puma/Http11.java | 150 ++++++++---------- .../org/jruby/puma/Http11Parser.java | 80 ++++------ 3 files changed, 110 insertions(+), 170 deletions(-) diff --git a/ext/puma_http11/http11_parser.java.rl b/ext/puma_http11/http11_parser.java.rl index d0ab2fc9..99fadca3 100644 --- a/ext/puma_http11/http11_parser.java.rl +++ b/ext/puma_http11/http11_parser.java.rl @@ -21,44 +21,35 @@ public class Http11Parser { } action start_value { parser.mark = fpc; } - action write_value { - if(parser.http_field != null) { - parser.http_field.call(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark); - } + action write_value { + Http11.http_field(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark); } - action request_method { - if(parser.request_method != null) - parser.request_method.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); + action request_method { + Http11.request_method(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); } - action request_uri { - if(parser.request_uri != null) - parser.request_uri.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); + action request_uri { + Http11.request_uri(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); } - action fragment { - if(parser.fragment != null) - parser.fragment.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); + action fragment { + Http11.fragment(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); } action start_query {parser.query_start = fpc; } - action query_string { - if(parser.query_string != null) - parser.query_string.call(runtime, parser.data, parser.buffer, parser.query_start, fpc-parser.query_start); + action query_string { + Http11.query_string(runtime, parser.data, parser.buffer, parser.query_start, fpc-parser.query_start); } - action http_version { - if(parser.http_version != null) - parser.http_version.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); + action http_version { + Http11.http_version(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); } action request_path { - if(parser.request_path != null) - parser.request_path.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); + Http11.request_path(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark); } action done { - parser.body_start = fpc + 1; - if(parser.header_done != null) - parser.header_done.call(runtime, parser.data, parser.buffer, fpc + 1, pe - fpc - 1); + parser.body_start = fpc + 1; + http.header_done(runtime, parser.data, parser.buffer, fpc + 1, pe - fpc - 1); fbreak; } @@ -90,15 +81,6 @@ public class Http11Parser { RubyHash data; ByteList buffer; - public FieldCB http_field; - public ElementCB request_method; - public ElementCB request_uri; - public ElementCB fragment; - public ElementCB request_path; - public ElementCB query_string; - public ElementCB http_version; - public ElementCB header_done; - public void init() { cs = 0; @@ -115,7 +97,7 @@ public class Http11Parser { public final HttpParser parser = new HttpParser(); - public int execute(Ruby runtime, ByteList buffer, int off) { + public int execute(Ruby runtime, Http11 http, ByteList buffer, int off) { int p, pe; int cs = parser.cs; int len = buffer.length(); diff --git a/ext/puma_http11/org/jruby/puma/Http11.java b/ext/puma_http11/org/jruby/puma/Http11.java index e0b7ee19..f6294192 100644 --- a/ext/puma_http11/org/jruby/puma/Http11.java +++ b/ext/puma_http11/org/jruby/puma/Http11.java @@ -70,14 +70,6 @@ public class Http11 extends RubyObject { super(runtime,clazz); this.runtime = runtime; this.hp = new Http11Parser(); - this.hp.parser.http_field = http_field; - this.hp.parser.request_method = request_method; - this.hp.parser.request_uri = request_uri; - this.hp.parser.fragment = fragment; - this.hp.parser.request_path = request_path; - this.hp.parser.query_string = query_string; - this.hp.parser.http_version = http_version; - this.hp.parser.header_done = header_done; this.hp.parser.init(); } @@ -96,93 +88,77 @@ public class Http11 extends RubyObject { return (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError"); } - private static Http11Parser.FieldCB http_field = new Http11Parser.FieldCB() { - public void call(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) { - RubyString f; - IRubyObject v; - validateMaxLength(runtime, flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR); - validateMaxLength(runtime, vlen, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR); + public static void http_field(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) { + RubyString f; + IRubyObject v; + validateMaxLength(runtime, flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR); + validateMaxLength(runtime, vlen, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR); - ByteList b = new ByteList(buffer,field,flen); - for(int i = 0,j = b.length();i