20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
22
#include " env-inl.h"
23
+ #include " node_debug.h"
23
24
#include " node_external_reference.h"
24
25
#include " string_bytes.h"
25
26
@@ -148,12 +149,26 @@ static void GetFreeMemory(const FunctionCallbackInfo<Value>& args) {
148
149
args.GetReturnValue ().Set (amount);
149
150
}
150
151
152
+ static double FastGetFreeMemory (Local<Value> receiver) {
153
+ TRACK_V8_FAST_API_CALL (" os.freemem" );
154
+ return static_cast <double >(uv_get_free_memory ());
155
+ }
156
+
157
+ static v8::CFunction fast_get_free_memory (
158
+ v8::CFunction::Make (FastGetFreeMemory));
151
159
152
160
static void GetTotalMemory (const FunctionCallbackInfo<Value>& args) {
153
161
double amount = static_cast <double >(uv_get_total_memory ());
154
162
args.GetReturnValue ().Set (amount);
155
163
}
156
164
165
+ double FastGetTotalMemory (Local<Value> receiver) {
166
+ TRACK_V8_FAST_API_CALL (" os.totalmem" );
167
+ return static_cast <double >(uv_get_total_memory ());
168
+ }
169
+
170
+ static v8::CFunction fast_get_total_memory (
171
+ v8::CFunction::Make (FastGetTotalMemory));
157
172
158
173
static void GetUptime (const FunctionCallbackInfo<Value>& args) {
159
174
Environment* env = Environment::GetCurrent (args);
@@ -406,6 +421,14 @@ static void GetAvailableParallelism(const FunctionCallbackInfo<Value>& args) {
406
421
args.GetReturnValue ().Set (parallelism);
407
422
}
408
423
424
+ uint32_t FastGetAvailableParallelism (v8::Local<v8::Value> receiver) {
425
+ TRACK_V8_FAST_API_CALL (" os.availableParallelism" );
426
+ return uv_available_parallelism ();
427
+ }
428
+
429
+ static v8::CFunction fast_get_available_parallelism (
430
+ v8::CFunction::Make (FastGetAvailableParallelism));
431
+
409
432
void Initialize (Local<Object> target,
410
433
Local<Value> unused,
411
434
Local<Context> context,
@@ -414,16 +437,21 @@ void Initialize(Local<Object> target,
414
437
SetMethod (context, target, " getHostname" , GetHostname);
415
438
SetMethod (context, target, " getLoadAvg" , GetLoadAvg);
416
439
SetMethod (context, target, " getUptime" , GetUptime);
417
- SetMethod (context, target, " getTotalMem" , GetTotalMemory);
418
- SetMethod (context, target, " getFreeMem" , GetFreeMemory);
440
+ SetFastMethodNoSideEffect (
441
+ context, target, " getTotalMem" , GetTotalMemory, &fast_get_total_memory);
442
+ SetFastMethodNoSideEffect (
443
+ context, target, " getFreeMem" , GetFreeMemory, &fast_get_free_memory);
419
444
SetMethod (context, target, " getCPUs" , GetCPUInfo);
420
445
SetMethod (context, target, " getInterfaceAddresses" , GetInterfaceAddresses);
421
446
SetMethod (context, target, " getHomeDirectory" , GetHomeDirectory);
422
447
SetMethod (context, target, " getUserInfo" , GetUserInfo);
423
448
SetMethod (context, target, " setPriority" , SetPriority);
424
449
SetMethod (context, target, " getPriority" , GetPriority);
425
- SetMethod (
426
- context, target, " getAvailableParallelism" , GetAvailableParallelism);
450
+ SetFastMethodNoSideEffect (context,
451
+ target,
452
+ " getAvailableParallelism" ,
453
+ GetAvailableParallelism,
454
+ &fast_get_available_parallelism);
427
455
SetMethod (context, target, " getOSInformation" , GetOSInformation);
428
456
target
429
457
->Set (context,
@@ -437,14 +465,20 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
437
465
registry->Register (GetLoadAvg);
438
466
registry->Register (GetUptime);
439
467
registry->Register (GetTotalMemory);
468
+ registry->Register (FastGetTotalMemory);
469
+ registry->Register (fast_get_total_memory.GetTypeInfo ());
440
470
registry->Register (GetFreeMemory);
471
+ registry->Register (FastGetFreeMemory);
472
+ registry->Register (fast_get_free_memory.GetTypeInfo ());
441
473
registry->Register (GetCPUInfo);
442
474
registry->Register (GetInterfaceAddresses);
443
475
registry->Register (GetHomeDirectory);
444
476
registry->Register (GetUserInfo);
445
477
registry->Register (SetPriority);
446
478
registry->Register (GetPriority);
447
479
registry->Register (GetAvailableParallelism);
480
+ registry->Register (FastGetAvailableParallelism);
481
+ registry->Register (fast_get_available_parallelism.GetTypeInfo ());
448
482
registry->Register (GetOSInformation);
449
483
}
450
484
0 commit comments