From 515f6aea84ad07a71a13fbaa1aec5251024707fc Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 9 Mar 2015 10:50:29 -0400 Subject: [PATCH] tls_wrap: proxy handle methods in prototype Set proxied methods wrappers in `TLSWrap` prototype instead of doing it on every socket allocation. Should speed up things a bit and will certainly make heapsnapshot less verbose. --- lib/_tls_wrap.js | 16 ++++++++-------- src/tls_wrap.cc | 7 +++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 2fd13ef83db1c9..fcc216bf289dfb 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -271,6 +271,14 @@ var proxiedMethods = [ 'setPendingInstances' ]; +// Proxy HandleWrap, PipeWrap and TCPWrap methods +proxiedMethods.forEach(function(name) { + tls_wrap.TLSWrap.prototype[name] = function methodProxy() { + if (this._parent[name]) + return this._parent[name].apply(this._parent, arguments); + }; +}); + TLSSocket.prototype._wrapHandle = function(handle) { var res; @@ -297,14 +305,6 @@ TLSSocket.prototype._wrapHandle = function(handle) { } }); - // Proxy HandleWrap, PipeWrap and TCPWrap methods - proxiedMethods.forEach(function(name) { - res[name] = function methodProxy() { - if (handle[name]) - return handle[name].apply(handle, arguments); - }; - }); - return res; }; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 8ecf33a75a98c5..49523bc3b84955 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -809,8 +809,8 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { void TLSWrap::Initialize(Handle target, - Handle unused, - Handle context) { + Handle unused, + Handle context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "wrap", TLSWrap::Wrap); @@ -835,6 +835,9 @@ void TLSWrap::Initialize(Handle target, env->set_tls_wrap_constructor_template(t); env->set_tls_wrap_constructor_function(t->GetFunction()); + + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"), + t->GetFunction()); } } // namespace node