From 48ed65440ca33fe6063d92379b3a9b10b65e98e9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 10 Sep 2016 17:50:02 +0200 Subject: src: pass desired return type to allocators Pass the desired return type directly to the allocation functions, so that the resulting `static_cast` from `void*` becomes unneccessary and the return type can be use as a reasonable default value for the `size` parameter. PR-URL: https://github.com/nodejs/node/pull/8482 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ilkka Myller --- src/string_bytes.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/string_bytes.cc') diff --git a/src/string_bytes.cc b/src/string_bytes.cc index fddf61de63..8acba5d55d 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -53,8 +53,7 @@ class ExternString: public ResourceType { if (length == 0) return scope.Escape(String::Empty(isolate)); - TypeName* new_data = - static_cast(node::Malloc(length, sizeof(*new_data))); + TypeName* new_data = node::Malloc(length); if (new_data == nullptr) { return Local(); } @@ -624,7 +623,7 @@ Local StringBytes::Encode(Isolate* isolate, case ASCII: if (contains_non_ascii(buf, buflen)) { - char* out = static_cast(node::Malloc(buflen)); + char* out = node::Malloc(buflen); if (out == nullptr) { return Local(); } @@ -659,7 +658,7 @@ Local StringBytes::Encode(Isolate* isolate, case BASE64: { size_t dlen = base64_encoded_size(buflen); - char* dst = static_cast(node::Malloc(dlen)); + char* dst = node::Malloc(dlen); if (dst == nullptr) { return Local(); } @@ -678,7 +677,7 @@ Local StringBytes::Encode(Isolate* isolate, case HEX: { size_t dlen = buflen * 2; - char* dst = static_cast(node::Malloc(dlen)); + char* dst = node::Malloc(dlen); if (dst == nullptr) { return Local(); } -- cgit v1.2.3