Skip to content

Commit 8431fc5

Browse files
committed
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. PR-URL: #1108 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 8070b1f commit 8431fc5

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/_tls_wrap.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ var proxiedMethods = [
271271
'setPendingInstances'
272272
];
273273

274+
// Proxy HandleWrap, PipeWrap and TCPWrap methods
275+
proxiedMethods.forEach(function(name) {
276+
tls_wrap.TLSWrap.prototype[name] = function methodProxy() {
277+
if (this._parent[name])
278+
return this._parent[name].apply(this._parent, arguments);
279+
};
280+
});
281+
274282
TLSSocket.prototype._wrapHandle = function(handle) {
275283
var res;
276284

@@ -297,14 +305,6 @@ TLSSocket.prototype._wrapHandle = function(handle) {
297305
}
298306
});
299307

300-
// Proxy HandleWrap, PipeWrap and TCPWrap methods
301-
proxiedMethods.forEach(function(name) {
302-
res[name] = function methodProxy() {
303-
if (handle[name])
304-
return handle[name].apply(handle, arguments);
305-
};
306-
});
307-
308308
return res;
309309
};
310310

src/tls_wrap.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
809809

810810

811811
void TLSWrap::Initialize(Handle<Object> target,
812-
Handle<Value> unused,
813-
Handle<Context> context) {
812+
Handle<Value> unused,
813+
Handle<Context> context) {
814814
Environment* env = Environment::GetCurrent(context);
815815

816816
env->SetMethod(target, "wrap", TLSWrap::Wrap);
@@ -835,6 +835,9 @@ void TLSWrap::Initialize(Handle<Object> target,
835835

836836
env->set_tls_wrap_constructor_template(t);
837837
env->set_tls_wrap_constructor_function(t->GetFunction());
838+
839+
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"),
840+
t->GetFunction());
838841
}
839842

840843
} // namespace node

0 commit comments

Comments
 (0)