mirror of https://github.com/nodejs/node.git
fs_event: use cached Persistent syms instead
Instead of String::New every time, use a Persistent sym. This can be accomplished in two ways: 1) Local<String> str = *persistent_str_sym; 2) Handle<String> str = persistent_str_sym; I've chosen to use the latter method for simplicity's sake. Other small changes include creating syms on Initialize and removing unnecessary Local casting on return values.pull/5010/head
parent
999ee45d36
commit
7998843807
|
@ -28,7 +28,9 @@ using namespace v8;
|
|||
|
||||
namespace node {
|
||||
|
||||
static Persistent<String> change_sym;
|
||||
static Persistent<String> onchange_sym;
|
||||
static Persistent<String> rename_sym;
|
||||
|
||||
class FSEventWrap: public HandleWrap {
|
||||
public:
|
||||
|
@ -76,6 +78,10 @@ void FSEventWrap::Initialize(Handle<Object> target) {
|
|||
target->Set(String::NewSymbol("FSEvent"),
|
||||
Persistent<FunctionTemplate>::New(node_isolate,
|
||||
t)->GetFunction());
|
||||
|
||||
change_sym = NODE_PSYMBOL("change");
|
||||
onchange_sym = NODE_PSYMBOL("onchange");
|
||||
rename_sym = NODE_PSYMBOL("rename");
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,7 +124,7 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
|
|||
void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
|
||||
int events, int status) {
|
||||
HandleScope scope(node_isolate);
|
||||
Local<String> eventStr;
|
||||
Handle<String> eventStr;
|
||||
|
||||
FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
|
||||
|
||||
|
@ -140,27 +146,22 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
|
|||
eventStr = String::Empty(node_isolate);
|
||||
}
|
||||
else if (events & UV_RENAME) {
|
||||
eventStr = String::New("rename");
|
||||
eventStr = rename_sym;
|
||||
}
|
||||
else if (events & UV_CHANGE) {
|
||||
eventStr = String::New("change");
|
||||
eventStr = change_sym;
|
||||
}
|
||||
else {
|
||||
assert(0 && "bad fs events flag");
|
||||
abort();
|
||||
}
|
||||
|
||||
Local<Value> argv[3] = {
|
||||
Handle<Value> argv[3] = {
|
||||
Integer::New(status, node_isolate),
|
||||
eventStr,
|
||||
filename ? static_cast<Local<Value> >(String::New(filename))
|
||||
: Local<Value>::New(node_isolate, v8::Null(node_isolate))
|
||||
filename ? String::New(filename) : v8::Null(node_isolate)
|
||||
};
|
||||
|
||||
if (onchange_sym.IsEmpty()) {
|
||||
onchange_sym = NODE_PSYMBOL("onchange");
|
||||
}
|
||||
|
||||
MakeCallback(wrap->object_, onchange_sym, ARRAY_SIZE(argv), argv);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue