Skip to content

Commit 355b96b

Browse files
committed
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: node-forward/node#55 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent 454fbb8 commit 355b96b

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/os.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var binding = process.binding('os');
2323
var util = require('util');
2424
var isWindows = process.platform === 'win32';
2525

26-
exports.endianness = binding.getEndianness;
2726
exports.hostname = binding.getHostname;
2827
exports.loadavg = binding.getLoadAvg;
2928
exports.uptime = binding.getUptime;
@@ -62,3 +61,8 @@ exports.getNetworkInterfaces = util.deprecate(function() {
6261
}, 'getNetworkInterfaces is now called `os.networkInterfaces`.');
6362

6463
exports.EOL = isWindows ? '\r\n' : '\n';
64+
65+
if (binding.isBigEndian)
66+
exports.endianness = function() { return 'BE'; };
67+
else
68+
exports.endianness = function() { return 'LE'; };

src/node_os.cc

+3-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace node {
4848
namespace os {
4949

5050
using v8::Array;
51+
using v8::Boolean;
5152
using v8::Context;
5253
using v8::FunctionCallbackInfo;
5354
using v8::Handle;
@@ -59,13 +60,6 @@ using v8::String;
5960
using v8::Value;
6061

6162

62-
static void GetEndianness(const FunctionCallbackInfo<Value>& args) {
63-
Environment* env = Environment::GetCurrent(args);
64-
const char* rval = IsBigEndian() ? "BE" : "LE";
65-
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
66-
}
67-
68-
6963
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
7064
Environment* env = Environment::GetCurrent(args);
7165
char buf[MAXHOSTNAMELEN + 1];
@@ -300,7 +294,6 @@ void Initialize(Handle<Object> target,
300294
Handle<Value> unused,
301295
Handle<Context> context) {
302296
Environment* env = Environment::GetCurrent(context);
303-
env->SetMethod(target, "getEndianness", GetEndianness);
304297
env->SetMethod(target, "getHostname", GetHostname);
305298
env->SetMethod(target, "getLoadAvg", GetLoadAvg);
306299
env->SetMethod(target, "getUptime", GetUptime);
@@ -310,6 +303,8 @@ void Initialize(Handle<Object> target,
310303
env->SetMethod(target, "getOSType", GetOSType);
311304
env->SetMethod(target, "getOSRelease", GetOSRelease);
312305
env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses);
306+
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"),
307+
Boolean::New(env->isolate(), IsBigEndian()));
313308
}
314309

315310
} // namespace os

0 commit comments

Comments
 (0)