Skip to content

Commit

Permalink
lib,src: make os.endianness() inlinable
Browse files Browse the repository at this point in the history
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: node-forward/node#55
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
bnoordhuis committed Nov 11, 2014
1 parent 454fbb8 commit 355b96b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'; };
11 changes: 3 additions & 8 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace node {
namespace os {

using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Handle;
Expand All @@ -59,13 +60,6 @@ using v8::String;
using v8::Value;


static void GetEndianness(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
const char* rval = IsBigEndian() ? "BE" : "LE";
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
}


static void GetHostname(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
char buf[MAXHOSTNAMELEN + 1];
Expand Down Expand Up @@ -300,7 +294,6 @@ void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> 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);
Expand All @@ -310,6 +303,8 @@ void Initialize(Handle<Object> 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
Expand Down

0 comments on commit 355b96b

Please sign in to comment.