From 4f394998bade0459a24eb8ce4b21aa6ba2386d03 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 13 Mar 2015 19:15:18 +0100 Subject: [PATCH 1/2] src: don't create js string twice on error Rewrite ErrnoException() so that it doesn't turn the file path into a string twice. PR-URL: https://github.com/iojs/io.js/pull/1148 Reviewed-By: Trevor Norris --- src/node.cc | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/node.cc b/src/node.cc index b2832086d37237..ba4118a6eb1766 100644 --- a/src/node.cc +++ b/src/node.cc @@ -724,28 +724,29 @@ Local ErrnoException(Isolate* isolate, } Local message = OneByteString(env->isolate(), msg); - Local cons1 = + Local cons = String::Concat(estring, FIXED_ONE_BYTE_STRING(env->isolate(), ", ")); - Local cons2 = String::Concat(cons1, message); + cons = String::Concat(cons, message); - if (path) { - Local cons3 = - String::Concat(cons2, FIXED_ONE_BYTE_STRING(env->isolate(), " '")); - Local cons4 = - String::Concat(cons3, String::NewFromUtf8(env->isolate(), path)); - Local cons5 = - String::Concat(cons4, FIXED_ONE_BYTE_STRING(env->isolate(), "'")); - e = Exception::Error(cons5); - } else { - e = Exception::Error(cons2); + Local path_string; + if (path != nullptr) { + // FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8. + path_string = String::NewFromUtf8(env->isolate(), path); } + if (path_string.IsEmpty() == false) { + cons = String::Concat(cons, FIXED_ONE_BYTE_STRING(env->isolate(), " '")); + cons = String::Concat(cons, path_string); + cons = String::Concat(cons, FIXED_ONE_BYTE_STRING(env->isolate(), "'")); + } + e = Exception::Error(cons); + Local obj = e->ToObject(env->isolate()); obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno)); obj->Set(env->code_string(), estring); - if (path != nullptr) { - obj->Set(env->path_string(), String::NewFromUtf8(env->isolate(), path)); + if (path_string.IsEmpty() == false) { + obj->Set(env->path_string(), path_string); } if (syscall != nullptr) { From 2551c1d2caaec21a5098de8e86274e0daf7aa781 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 13 Mar 2015 21:54:40 +0100 Subject: [PATCH 2/2] src: use Number::New() for heapTotal/heapUsed With --max_old_space_size=12345 it's possible to create a JS heap that is larger than what fits in an unsigned int so use Number::New() rather than Integer::NewFromUnsigned(). Performance-wise, it doesn't matter much. If V8 can fit the double in a SMI, it will. PR-URL: https://github.com/iojs/io.js/pull/1148 Reviewed-By: Trevor Norris --- src/node.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index ba4118a6eb1766..5e906fe68430e4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1932,10 +1932,10 @@ void MemoryUsage(const FunctionCallbackInfo& args) { HeapStatistics v8_heap_stats; env->isolate()->GetHeapStatistics(&v8_heap_stats); - Local heap_total = - Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.total_heap_size()); - Local heap_used = - Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.used_heap_size()); + Local heap_total = + Number::New(env->isolate(), v8_heap_stats.total_heap_size()); + Local heap_used = + Number::New(env->isolate(), v8_heap_stats.used_heap_size()); Local info = Object::New(env->isolate()); info->Set(env->rss_string(), Number::New(env->isolate(), rss));