Skip to content

Commit

Permalink
tls_wrap: proxy handle methods in prototype
Browse files Browse the repository at this point in the history
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.

PR-URL: #1108
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
indutny committed Mar 9, 2015
1 parent 8070b1f commit 8431fc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
};

Expand Down
7 changes: 5 additions & 2 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {


void TLSWrap::Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);

env->SetMethod(target, "wrap", TLSWrap::Wrap);
Expand All @@ -835,6 +835,9 @@ void TLSWrap::Initialize(Handle<Object> 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
Expand Down

0 comments on commit 8431fc5

Please sign in to comment.