Skip to content

Commit

Permalink
dns: allow v8 to optimize lookup()
Browse files Browse the repository at this point in the history
Using `arguments` and reassigning parameter variable
values causes v8 to disable function optimization.

PR-URL: nodejs/node-v0.x-archive#8942
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex authored and jasnell committed Aug 27, 2015
1 parent 66ec1da commit 6502160
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var cares = process.binding('cares_wrap'),
net = require('net'),
isIp = net.isIP;
isIP = net.isIP;


function errnoException(errorno, syscall) {
Expand Down Expand Up @@ -78,7 +78,9 @@ function makeAsync(callback) {

// Easy DNS A/AAAA look up
// lookup(domain, [family,] callback)
exports.lookup = function(domain, family, callback) {
exports.lookup = function(domain, family_, callback_) {
var family = family_,
callback = callback_;
// parse arguments
if (arguments.length === 2) {
callback = family;
Expand All @@ -102,12 +104,12 @@ exports.lookup = function(domain, family, callback) {
// localhost entry from c:\WINDOWS\system32\drivers\etc\hosts
// See http://daniel.haxx.se/blog/2011/02/21/localhost-hack-on-windows/
// TODO Remove this once c-ares handles this problem.
if (process.platform == 'win32' && domain == 'localhost') {
if (process.platform === 'win32' && domain === 'localhost') {
callback(null, '127.0.0.1', 4);
return {};
}

var matchedFamily = net.isIP(domain);
var matchedFamily = isIP(domain);
if (matchedFamily) {
callback(null, domain, matchedFamily);
return {};
Expand Down

0 comments on commit 6502160

Please sign in to comment.