summaryrefslogtreecommitdiff
path: root/src/string_bytes.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-09-10 17:50:02 +0200
committerAnna Henningsen <anna@addaleax.net>2016-09-29 09:46:42 +0200
commit48ed65440ca33fe6063d92379b3a9b10b65e98e9 (patch)
treeb0fbfa17238c7d00839b92f3712e39c468c77c0a /src/string_bytes.cc
parenteb927fac38a50252e11ebe0da1764e85294f95f0 (diff)
downloadandroid-node-v8-48ed65440ca33fe6063d92379b3a9b10b65e98e9.tar.gz
android-node-v8-48ed65440ca33fe6063d92379b3a9b10b65e98e9.tar.bz2
android-node-v8-48ed65440ca33fe6063d92379b3a9b10b65e98e9.zip
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 <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r--src/string_bytes.cc9
1 files changed, 4 insertions, 5 deletions
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<TypeName*>(node::Malloc(length, sizeof(*new_data)));
+ TypeName* new_data = node::Malloc<TypeName>(length);
if (new_data == nullptr) {
return Local<String>();
}
@@ -624,7 +623,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
case ASCII:
if (contains_non_ascii(buf, buflen)) {
- char* out = static_cast<char*>(node::Malloc(buflen));
+ char* out = node::Malloc(buflen);
if (out == nullptr) {
return Local<String>();
}
@@ -659,7 +658,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
case BASE64: {
size_t dlen = base64_encoded_size(buflen);
- char* dst = static_cast<char*>(node::Malloc(dlen));
+ char* dst = node::Malloc(dlen);
if (dst == nullptr) {
return Local<String>();
}
@@ -678,7 +677,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
case HEX: {
size_t dlen = buflen * 2;
- char* dst = static_cast<char*>(node::Malloc(dlen));
+ char* dst = node::Malloc(dlen);
if (dst == nullptr) {
return Local<String>();
}