GeezerVison is showing github.com — src,buffer: remove unused chars_written parameter · e7dal/node@6e418ff
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/encoding.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,7 +150,7 @@ ssize_t DecodeWrite(Isolate* isolate, | 150 | 150 | size_t buflen, | 151 | 151 | Local<Value> val, | 152 | 152 | enum encoding encoding) { | 153 | | - return StringBytes::Write(isolate, buf, buflen, val, encoding, nullptr); | | 153 | + return StringBytes::Write(isolate, buf, buflen, val, encoding); | 154 | 154 | } | 155 | 155 |
| 156 | 156 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/node_buffer.cc +4-12Lines changed: 4 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -666,12 +666,8 @@ void Fill(const FunctionCallbackInfo<Value>& args) { | 666 | 666 | // Write initial String to Buffer, then use that memory to copy remainder | 667 | 667 | // of string. Correct the string length for cases like HEX where less than | 668 | 668 | // the total string length is written. | 669 | | - str_length = StringBytes::Write(env->isolate(), | 670 | | - ts_obj_data + start, | 671 | | - fill_length, | 672 | | - str_obj, | 673 | | - enc, | 674 | | - nullptr); | | 669 | + str_length = StringBytes::Write( | | 670 | + env->isolate(), ts_obj_data + start, fill_length, str_obj, enc); | 675 | 671 | } | 676 | 672 |
| 677 | 673 | start_fill: | @@ -730,12 +726,8 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) { | 730 | 726 | if (max_length == 0) | 731 | 727 | return args.GetReturnValue().Set(0); | 732 | 728 |
| 733 | | - uint32_t written = StringBytes::Write(env->isolate(), | 734 | | - ts_obj_data + offset, | 735 | | - max_length, | 736 | | - str, | 737 | | - encoding, | 738 | | - nullptr); | | 729 | + uint32_t written = StringBytes::Write( | | 730 | + env->isolate(), ts_obj_data + offset, max_length, str, encoding); | 739 | 731 | args.GetReturnValue().Set(written); | 740 | 732 | } | 741 | 733 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/string_bytes.cc +8-25Lines changed: 8 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -260,12 +260,8 @@ static size_t hex_decode(char* buf, | 260 | 260 | return i; | 261 | 261 | } | 262 | 262 |
| 263 | | -size_t StringBytes::WriteUCS2(Isolate* isolate, | 264 | | - char* buf, | 265 | | - size_t buflen, | 266 | | - Local<String> str, | 267 | | - int flags, | 268 | | - size_t* chars_written) { | | 263 | +size_t StringBytes::WriteUCS2( | | 264 | + Isolate* isolate, char* buf, size_t buflen, Local<String> str, int flags) { | 269 | 265 | uint16_t* const dst = reinterpret_cast<uint16_t*>(buf); | 270 | 266 |
| 271 | 267 | size_t max_chars = buflen / sizeof(*dst); | @@ -277,15 +273,16 @@ size_t StringBytes::WriteUCS2(Isolate* isolate, | 277 | 273 | size_t nchars; | 278 | 274 | if (aligned_dst == dst) { | 279 | 275 | nchars = str->Write(isolate, dst, 0, max_chars, flags); | 280 | | - *chars_written = nchars; | 281 | 276 | return nchars * sizeof(*dst); | 282 | 277 | } | 283 | 278 |
| 284 | 279 | CHECK_EQ(reinterpret_cast<uintptr_t>(aligned_dst) % sizeof(*dst), 0); | 285 | 280 |
| 286 | 281 | // Write all but the last char | 287 | 282 | max_chars = std::min(max_chars, static_cast<size_t>(str->Length())); | 288 | | - if (max_chars == 0) return 0; | | 283 | + if (max_chars == 0) { | | 284 | + return 0; | | 285 | + } | 289 | 286 | nchars = str->Write(isolate, aligned_dst, 0, max_chars - 1, flags); | 290 | 287 | CHECK_EQ(nchars, max_chars - 1); | 291 | 288 |
| @@ -298,23 +295,16 @@ size_t StringBytes::WriteUCS2(Isolate* isolate, | 298 | 295 | memcpy(buf + nchars * sizeof(*dst), &last, sizeof(last)); | 299 | 296 | nchars++; | 300 | 297 |
| 301 | | - *chars_written = nchars; | 302 | 298 | return nchars * sizeof(*dst); | 303 | 299 | } | 304 | 300 |
| 305 | | - | 306 | 301 | size_t StringBytes::Write(Isolate* isolate, | 307 | 302 | char* buf, | 308 | 303 | size_t buflen, | 309 | 304 | Local<Value> val, | 310 | | - enum encoding encoding, | 311 | | - int* chars_written) { | | 305 | + enum encoding encoding) { | 312 | 306 | HandleScope scope(isolate); | 313 | 307 | size_t nbytes; | 314 | | - int nchars; | 315 | | - | 316 | | - if (chars_written == nullptr) | 317 | | - chars_written = &nchars; | 318 | 308 |
| 319 | 309 | CHECK(val->IsString() == true); | 320 | 310 | Local<String> str = val.As<String>(); | @@ -334,19 +324,15 @@ size_t StringBytes::Write(Isolate* isolate, | 334 | 324 | uint8_t* const dst = reinterpret_cast<uint8_t*>(buf); | 335 | 325 | nbytes = str->WriteOneByte(isolate, dst, 0, buflen, flags); | 336 | 326 | } | 337 | | - *chars_written = nbytes; | 338 | 327 | break; | 339 | 328 |
| 340 | 329 | case BUFFER: | 341 | 330 | case UTF8: | 342 | | - nbytes = str->WriteUtf8(isolate, buf, buflen, chars_written, flags); | | 331 | + nbytes = str->WriteUtf8(isolate, buf, buflen, nullptr, flags); | 343 | 332 | break; | 344 | 333 |
| 345 | 334 | case UCS2: { | 346 | | - size_t nchars; | 347 | | - | 348 | | - nbytes = WriteUCS2(isolate, buf, buflen, str, flags, &nchars); | 349 | | - *chars_written = static_cast<int>(nchars); | | 335 | + nbytes = WriteUCS2(isolate, buf, buflen, str, flags); | 350 | 336 |
| 351 | 337 | // Node's "ucs2" encoding wants LE character data stored in | 352 | 338 | // the Buffer, so we need to reorder on BE platforms. See | @@ -368,7 +354,6 @@ size_t StringBytes::Write(Isolate* isolate, | 368 | 354 | String::Value value(isolate, str); | 369 | 355 | nbytes = base64_decode(buf, buflen, *value, value.length()); | 370 | 356 | } | 371 | | - *chars_written = nbytes; | 372 | 357 | break; | 373 | 358 |
| 374 | 359 | case HEX: | @@ -379,7 +364,6 @@ size_t StringBytes::Write(Isolate* isolate, | 379 | 364 | String::Value value(isolate, str); | 380 | 365 | nbytes = hex_decode(buf, buflen, *value, value.length()); | 381 | 366 | } | 382 | | - *chars_written = nbytes; | 383 | 367 | break; | 384 | 368 |
| 385 | 369 | default: | @@ -390,7 +374,6 @@ size_t StringBytes::Write(Isolate* isolate, | 390 | 374 | return nbytes; | 391 | 375 | } | 392 | 376 |
| 393 | | - | 394 | 377 | // Quick and dirty size calculation | 395 | 378 | // Will always be at least big enough, but may have some extra | 396 | 379 | // UTF8 can be as much as 3x the size, Base64 can have 1-2 extra bytes | |
Collapse file Copy file name to clipboardExpand all lines: src/string_bytes.h +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,8 +75,7 @@ class StringBytes { | 75 | 75 | char* buf, | 76 | 76 | size_t buflen, | 77 | 77 | v8::Local<v8::Value> val, | 78 | | - enum encoding enc, | 79 | | - int* chars_written = nullptr); | | 78 | + enum encoding enc); | 80 | 79 |
| 81 | 80 | // Take the bytes in the src, and turn it into a Buffer or String. | 82 | 81 | static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate, | @@ -111,8 +110,7 @@ class StringBytes { | 111 | 110 | char* buf, | 112 | 111 | size_t buflen, | 113 | 112 | v8::Local<v8::String> str, | 114 | | - int flags, | 115 | | - size_t* chars_written); | | 113 | + int flags); | 116 | 114 | }; | 117 | 115 |
| 118 | 116 | } // namespace node | |
|