mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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. Backport-PR-URL: https://github.com/nodejs/node/pull/16587 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>
This commit is contained in:
1 parent
19f3ac9749
commit
4aec8cfcd2
11 files changed
+68
-57
No files matched your search
+4
-5
@@ -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>();
|
||||
}
|
||||
@@ -610,7 +609,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>();
|
||||
}
|
||||
@@ -645,7 +644,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>();
|
||||
}
|
||||
@@ -664,7 +663,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>();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user