diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-03 03:42:18 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-05 22:42:13 +0300 |
commit | 826cde866170918fbeeeffc8612d4f4e0a923869 (patch) | |
tree | 65641ca03ca7630db2e3e4cce4b281e711832e25 /src/string_bytes.cc | |
parent | f5b7e18243b25a39ec53890344f9353a1b54d6cd (diff) |
src: fix gc heuristic for external twobyte strings
Large external two-byte strings reported their character length instead
of their byte length, throwing off the garbage collector heuristic by
a factor of two.
PR-URL: https://github.com/iojs/io.js/pull/1042
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 7b07c6b7da1..c828363da6d 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -28,8 +28,7 @@ class ExternString: public ResourceType { public: ~ExternString() override { delete[] data_; - int64_t change_in_bytes = -static_cast<int64_t>(length_); - isolate()->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); + isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length()); } const TypeName* data() const override { @@ -40,6 +39,10 @@ class ExternString: public ResourceType { return length_; } + int64_t byte_length() const { + return length() * sizeof(*data()); + } + static Local<String> NewFromCopy(Isolate* isolate, const TypeName* data, size_t length) { @@ -69,7 +72,7 @@ class ExternString: public ResourceType { data, length); Local<String> str = String::NewExternal(isolate, h_str); - isolate->AdjustAmountOfExternalAllocatedMemory(length); + isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length()); return scope.Escape(str); } |