@@ -17,7 +17,7 @@ namespace nodex {
1717 using v8::Value;
1818
1919 Nan::Persistent<ObjectTemplate> Profile::profile_template_;
20- Nan::Persistent<Array > Profile::profiles;
20+ Nan::Persistent<Object > Profile::profiles;
2121 uint32_t Profile::uid_counter = 0 ;
2222
2323 NAN_METHOD (Profile_EmptyMethod) {
@@ -36,19 +36,10 @@ namespace nodex {
3636 NAN_METHOD (Profile::Delete) {
3737 Local<Object> self = info.This ();
3838 void * ptr = Nan::GetInternalFieldPointer (self, 0 );
39- Local<Array> profiles = Nan::New<Array>(Profile::profiles);
40-
41- uint32_t count = profiles->Length ();
42- for (uint32_t index = 0 ; index < count; index++) {
43- if (profiles->Get (index) == info.This ()) {
44- Local<Value> argv[2 ] = {
45- Nan::New<Integer>(index),
46- Nan::New<Integer>(1 )
47- };
48- Local<Function>::Cast (profiles->Get (Nan::New<String>(" splice" ).ToLocalChecked ()))->Call (profiles, 2 , argv);
49- break ;
50- }
51- }
39+ Local<Object> profiles = Nan::New<Object>(Profile::profiles);
40+ Local<Value> _uid = info.This ()->Get (Nan::New<String>(" uid" ).ToLocalChecked ());
41+ Local<String> uid = Nan::To<String>(_uid).ToLocalChecked ();
42+ profiles->Delete (uid);
5243 static_cast <CpuProfile*>(ptr)->Delete ();
5344 }
5445
@@ -64,15 +55,19 @@ namespace nodex {
6455 Local<Object> profile = Nan::New (profile_template_)->NewInstance ();
6556 Nan::SetInternalFieldPointer (profile, 0 , const_cast <CpuProfile*>(node));
6657
58+ uint32_t uid_length = (((sizeof uid_counter) * 8 ) + 2 )/3 + 2 ;
59+ char _uid[uid_length];
60+ sprintf (_uid, " %d" , uid_counter);
61+
6762 Local<Value> CPU = Nan::New<String>(" CPU" ).ToLocalChecked ();
68- Local<Value> uid = Nan::New<Integer>(uid_counter );
63+ Local<Value> uid = Nan::New<String>(_uid). ToLocalChecked ( );
6964#if (NODE_MODULE_VERSION >= 45)
7065 Local<String> title = node->GetTitle ();
7166#else
7267 Local<String> title = Nan::New (node->GetTitle ());
7368#endif
7469 if (!title->Length ()) {
75- char _title[32 ];
70+ char _title[8 + uid_length ];
7671 sprintf (_title, " Profile %i" , uid_counter);
7772 title = Nan::New<String>(_title).ToLocalChecked ();
7873 }
@@ -101,8 +96,8 @@ namespace nodex {
10196 profile->Set (Nan::New<String>(" timestamps" ).ToLocalChecked (), timestamps);
10297#endif
10398
104- Local<Array > profiles = Nan::New<Array >(Profile::profiles);
105- profiles->Set (profiles-> Length () , profile);
99+ Local<Object > profiles = Nan::New<Object >(Profile::profiles);
100+ profiles->Set (uid , profile);
106101
107102 return scope.Escape (profile);
108103 }
0 commit comments