Run(): to run the compiled script.
The Run() will be called more than 100,000,000 times. Could you give us some suggestions to optimize this part?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
void Init(char *strJavaScript)
{
strScript = strJavaScript;
this->isolate = Isolate::New();
isolate->Enter();
Isolate::Scope isolate_scope(this->isolate);
HandleScope handle_scope(this->isolate);
Handle<ObjectTemplate> templ = ObjectTemplate::New(this->isolate);
templ->SetAccessor(v8_str("inputStr"), getStringValue, setStringValue, External::New(this->isolate, &inputStr));
templ->SetAccessor(v8_str("inputNum"), getIntValue, setIntValue, External::New(this->isolate, &inputNum));
templ->SetAccessor(v8_str("outputStr"), getStringValue, setStringValue, External::New(this->isolate, &outputStr));
templ->SetAccessor(v8_str("outputNum"), getIntValue, setIntValue, External::New(this->isolate, &outputNum));
Handle<Context> context = Context::New(isolate, NULL, templ);
_context = Persistent<Context, CopyablePersistentTraits<Context>>(isolate, context);
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::NewFromUtf8(isolate, strScript);
// Compile the given JavaScript
Handle<Script> script = Script::Compile(source);
_script = Persistent<Script, CopyablePersistentTraits<Script>>(isolate, script);
}
void Run()
{
HandleScope scope(Isolate::GetCurrent());
Context::Scope context_scope(Local<Context>::New(Isolate::GetCurrent(), this->_context));
Local<Value> result = Local<Script>::New(Isolate::GetCurrent(), this->_script)->Run();
}