@@ -1079,38 +1079,23 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) { |
1079 | 1079 | int64_t pos = GET_OFFSET(args[2]); |
1080 | 1080 | Local<Value> req = args[3]; |
1081 | 1081 |
|
1082 | | - uint32_t chunkCount = chunks->Length(); |
| 1082 | + MaybeStackBuffer<uv_buf_t> iovs(chunks->Length()); |
1083 | 1083 |
|
1084 | | - uv_buf_t s_iovs[1024]; // use stack allocation when possible |
1085 | | - uv_buf_t* iovs; |
1086 | | - |
1087 | | - if (chunkCount > arraysize(s_iovs)) |
1088 | | - iovs = new uv_buf_t[chunkCount]; |
1089 | | - else |
1090 | | - iovs = s_iovs; |
1091 | | - |
1092 | | - for (uint32_t i = 0; i < chunkCount; i++) { |
| 1084 | + for (uint32_t i = 0; i < iovs.length(); i++) { |
1093 | 1085 | Local<Value> chunk = chunks->Get(i); |
1094 | 1086 |
|
1095 | | - if (!Buffer::HasInstance(chunk)) { |
1096 | | - if (iovs != s_iovs) |
1097 | | - delete[] iovs; |
| 1087 | + if (!Buffer::HasInstance(chunk)) |
1098 | 1088 | return env->ThrowTypeError("Array elements all need to be buffers"); |
1099 | | - } |
1100 | 1089 |
|
1101 | 1090 | iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk)); |
1102 | 1091 | } |
1103 | 1092 |
|
1104 | 1093 | if (req->IsObject()) { |
1105 | | - ASYNC_CALL(write, req, UTF8, fd, iovs, chunkCount, pos) |
1106 | | - if (iovs != s_iovs) |
1107 | | - delete[] iovs; |
| 1094 | + ASYNC_CALL(write, req, UTF8, fd, *iovs, iovs.length(), pos) |
1108 | 1095 | return; |
1109 | 1096 | } |
1110 | 1097 |
|
1111 | | - SYNC_CALL(write, nullptr, fd, iovs, chunkCount, pos) |
1112 | | - if (iovs != s_iovs) |
1113 | | - delete[] iovs; |
| 1098 | + SYNC_CALL(write, nullptr, fd, *iovs, iovs.length(), pos) |
1114 | 1099 | args.GetReturnValue().Set(SYNC_RESULT); |
1115 | 1100 | } |
1116 | 1101 |
|
|