From 6f5502a5022d2da69f0a151f54708642fcbaff2a Mon Sep 17 00:00:00 2001 From: akhil Date: Mon, 24 Feb 2014 14:38:55 -0800 Subject: [PATCH] reduce the number of jni calls by passing some values in header callback --- .../oracle/avatar/js/http/ParserSettings.java | 40 ++++++++++++++----- .../com/oracle/avatar/js/http_parser_wrap.js | 26 ++++-------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/oracle/avatar/js/http/ParserSettings.java b/src/main/java/com/oracle/avatar/js/http/ParserSettings.java index 11928c6..9a5f949 100644 --- a/src/main/java/com/oracle/avatar/js/http/ParserSettings.java +++ b/src/main/java/com/oracle/avatar/js/http/ParserSettings.java @@ -30,23 +30,36 @@ import com.oracle.httpparser.HttpParserSettings; public final class ParserSettings extends HttpParserSettings { public interface ParserDataFunction { - public int call(int offset, int length); + public int call(int offset, + int length); } public interface ParserFunction { public int call(); } - public interface ParserHeadersFunction { - public int call(String url, String[] headers); + public interface ParserHeadersFunction { + public int call(String url, + String[] headers); } - final ParserHeadersFunction onHeadersComplete; + public interface ParserHeadersCompleteFunction { + public int call(String url, + String[] headers, + String method, + int status, + int httpVersionMajor, + int httpVersionMinor, + boolean shouldKeepAlive, + boolean upgrade); + } + + final ParserHeadersCompleteFunction onHeadersComplete; final ParserDataFunction onBody; final ParserFunction onMessageComplete; final ParserHeadersFunction onHeaders; - public ParserSettings(final ParserHeadersFunction onHeadersComplete, + public ParserSettings(final ParserHeadersCompleteFunction onHeadersComplete, final ParserDataFunction onBody, final ParserFunction onMessageComplete, final ParserHeadersFunction onHeaders) { @@ -57,16 +70,25 @@ public final class ParserSettings extends HttpParserSettings { } @Override - public int onHeadersComplete(String url, String[] headers) { - return onHeadersComplete.call(url, headers); + public int onHeadersComplete(String url, + String[] headers, + String method, + int status, + int httpVersionMajor, + int httpVersionMinor, + boolean shouldKeepAlive, + boolean upgrade) { + return onHeadersComplete.call(url, headers, method, status, httpVersionMajor, httpVersionMinor, shouldKeepAlive, upgrade); } @Override - public int onHeaders(String url, String[] headers) { + public int onHeaders(String url, + String[] headers) { return onHeaders.call(url, headers); } @Override - public int onBody(int offset, int length) { + public int onBody(int offset, + int length) { return onBody.call(offset, length); } diff --git a/src/main/js/com/oracle/avatar/js/http_parser_wrap.js b/src/main/js/com/oracle/avatar/js/http_parser_wrap.js index fa453b7..4c46ca8 100644 --- a/src/main/js/com/oracle/avatar/js/http_parser_wrap.js +++ b/src/main/js/com/oracle/avatar/js/http_parser_wrap.js @@ -37,38 +37,26 @@ function HTTPParser(type) { this.reinitialize(type); - Object.defineProperty(this, 'minor', { - get : function() { - this._parser.minor() - } - }); - Object.defineProperty(this, 'major', { - get : function() { - this._parser.major() - } - }); - var that = this; - Object.defineProperty(this, '_settings', { value : new ParserSettings( // on_headers_complete - function(url, jheaders) { + function(url, jheaders, method, status, httpVersionMajor, httpVersionMinor, shouldKeepAlive, upgrade) { var headers = Java.from(jheaders); var info = { headers : headers, - versionMinor : that._parser.minor(), - versionMajor : that._parser.major(), - shouldKeepAlive : that._parser.shouldKeepAlive(), - upgrade : that._parser.upgrade() + versionMinor : httpVersionMinor, + versionMajor : httpVersionMajor, + shouldKeepAlive : shouldKeepAlive, + upgrade : upgrade }; if (that._type === HTTPParser.REQUEST) { info.url = url; - info.method = that._parser.method(); + info.method = method; } if (that._type === HTTPParser.RESPONSE) { - info.statusCode = that._parser.statusCode(); + info.statusCode = status; } var response;