From: Ben Noordhuis Date: Mon, 10 Nov 2014 23:40:58 +0000 (+0100) Subject: lib,src: make os.endianness() inlinable X-Git-Tag: v1.0.0~281 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=355b96b605592d753f7381709e4827fa2e5ee29d;p=platform%2Fupstream%2Fnodejs.git lib,src: make os.endianness() inlinable Turn os.endianness() from a run-time function into a pure JS function. Upsides: makes it a good candidate for inlining at the call site. Downsides: none that I can think of. PR-URL: https://github.com/node-forward/node/pull/55 Reviewed-By: Chris Dickinson Reviewed-By: Colin Ihrig Reviewed-By: Fedor Indutny --- diff --git a/lib/os.js b/lib/os.js index 814c054..9fc4673 100644 --- a/lib/os.js +++ b/lib/os.js @@ -23,7 +23,6 @@ var binding = process.binding('os'); var util = require('util'); var isWindows = process.platform === 'win32'; -exports.endianness = binding.getEndianness; exports.hostname = binding.getHostname; exports.loadavg = binding.getLoadAvg; exports.uptime = binding.getUptime; @@ -62,3 +61,8 @@ exports.getNetworkInterfaces = util.deprecate(function() { }, 'getNetworkInterfaces is now called `os.networkInterfaces`.'); exports.EOL = isWindows ? '\r\n' : '\n'; + +if (binding.isBigEndian) + exports.endianness = function() { return 'BE'; }; +else + exports.endianness = function() { return 'LE'; }; diff --git a/src/node_os.cc b/src/node_os.cc index 9341ee6..e4d9023 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -48,6 +48,7 @@ namespace node { namespace os { using v8::Array; +using v8::Boolean; using v8::Context; using v8::FunctionCallbackInfo; using v8::Handle; @@ -59,13 +60,6 @@ using v8::String; using v8::Value; -static void GetEndianness(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - const char* rval = IsBigEndian() ? "BE" : "LE"; - args.GetReturnValue().Set(OneByteString(env->isolate(), rval)); -} - - static void GetHostname(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); char buf[MAXHOSTNAMELEN + 1]; @@ -300,7 +294,6 @@ void Initialize(Handle target, Handle unused, Handle context) { Environment* env = Environment::GetCurrent(context); - env->SetMethod(target, "getEndianness", GetEndianness); env->SetMethod(target, "getHostname", GetHostname); env->SetMethod(target, "getLoadAvg", GetLoadAvg); env->SetMethod(target, "getUptime", GetUptime); @@ -310,6 +303,8 @@ void Initialize(Handle target, env->SetMethod(target, "getOSType", GetOSType); env->SetMethod(target, "getOSRelease", GetOSRelease); env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"), + Boolean::New(env->isolate(), IsBigEndian())); } } // namespace os