2020// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
2222#include " env-inl.h"
23+ #include " node_debug.h"
2324#include " node_external_reference.h"
2425#include " string_bytes.h"
2526
@@ -148,12 +149,26 @@ static void GetFreeMemory(const FunctionCallbackInfo<Value>& args) {
148149 args.GetReturnValue ().Set (amount);
149150}
150151
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));
151159
152160static void GetTotalMemory (const FunctionCallbackInfo<Value>& args) {
153161 double amount = static_cast <double >(uv_get_total_memory ());
154162 args.GetReturnValue ().Set (amount);
155163}
156164
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));
157172
158173static void GetUptime (const FunctionCallbackInfo<Value>& args) {
159174 Environment* env = Environment::GetCurrent (args);
@@ -398,6 +413,14 @@ static void GetAvailableParallelism(const FunctionCallbackInfo<Value>& args) {
398413 args.GetReturnValue ().Set (parallelism);
399414}
400415
416+ uint32_t FastGetAvailableParallelism (v8::Local<v8::Value> receiver) {
417+ TRACK_V8_FAST_API_CALL (" os.availableParallelism" );
418+ return uv_available_parallelism ();
419+ }
420+
421+ static v8::CFunction fast_get_available_parallelism (
422+ v8::CFunction::Make (FastGetAvailableParallelism));
423+
401424void Initialize (Local<Object> target,
402425 Local<Value> unused,
403426 Local<Context> context,
@@ -406,16 +429,21 @@ void Initialize(Local<Object> target,
406429 SetMethod (context, target, " getHostname" , GetHostname);
407430 SetMethod (context, target, " getLoadAvg" , GetLoadAvg);
408431 SetMethod (context, target, " getUptime" , GetUptime);
409- SetMethod (context, target, " getTotalMem" , GetTotalMemory);
410- SetMethod (context, target, " getFreeMem" , GetFreeMemory);
432+ SetFastMethodNoSideEffect (
433+ context, target, " getTotalMem" , GetTotalMemory, &fast_get_total_memory);
434+ SetFastMethodNoSideEffect (
435+ context, target, " getFreeMem" , GetFreeMemory, &fast_get_free_memory);
411436 SetMethod (context, target, " getCPUs" , GetCPUInfo);
412437 SetMethod (context, target, " getInterfaceAddresses" , GetInterfaceAddresses);
413438 SetMethod (context, target, " getHomeDirectory" , GetHomeDirectory);
414439 SetMethod (context, target, " getUserInfo" , GetUserInfo);
415440 SetMethod (context, target, " setPriority" , SetPriority);
416441 SetMethod (context, target, " getPriority" , GetPriority);
417- SetMethod (
418- context, target, " getAvailableParallelism" , GetAvailableParallelism);
442+ SetFastMethodNoSideEffect (context,
443+ target,
444+ " getAvailableParallelism" ,
445+ GetAvailableParallelism,
446+ &fast_get_available_parallelism);
419447 SetMethod (context, target, " getOSInformation" , GetOSInformation);
420448 target
421449 ->Set (context,
@@ -429,14 +457,20 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
429457 registry->Register (GetLoadAvg);
430458 registry->Register (GetUptime);
431459 registry->Register (GetTotalMemory);
460+ registry->Register (FastGetTotalMemory);
461+ registry->Register (fast_get_total_memory.GetTypeInfo ());
432462 registry->Register (GetFreeMemory);
463+ registry->Register (FastGetFreeMemory);
464+ registry->Register (fast_get_free_memory.GetTypeInfo ());
433465 registry->Register (GetCPUInfo);
434466 registry->Register (GetInterfaceAddresses);
435467 registry->Register (GetHomeDirectory);
436468 registry->Register (GetUserInfo);
437469 registry->Register (SetPriority);
438470 registry->Register (GetPriority);
439471 registry->Register (GetAvailableParallelism);
472+ registry->Register (FastGetAvailableParallelism);
473+ registry->Register (fast_get_available_parallelism.GetTypeInfo ());
440474 registry->Register (GetOSInformation);
441475}
442476
0 commit comments