@@ -260,12 +260,8 @@ static size_t hex_decode(char* buf,
260260 return i;
261261}
262262
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) {
269265 uint16_t * const dst = reinterpret_cast <uint16_t *>(buf);
270266
271267 size_t max_chars = buflen / sizeof (*dst);
@@ -277,15 +273,16 @@ size_t StringBytes::WriteUCS2(Isolate* isolate,
277273 size_t nchars;
278274 if (aligned_dst == dst) {
279275 nchars = str->Write (isolate, dst, 0 , max_chars, flags);
280- *chars_written = nchars;
281276 return nchars * sizeof (*dst);
282277 }
283278
284279 CHECK_EQ (reinterpret_cast <uintptr_t >(aligned_dst) % sizeof (*dst), 0 );
285280
286281 // Write all but the last char
287282 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+ }
289286 nchars = str->Write (isolate, aligned_dst, 0 , max_chars - 1 , flags);
290287 CHECK_EQ (nchars, max_chars - 1 );
291288
@@ -298,23 +295,16 @@ size_t StringBytes::WriteUCS2(Isolate* isolate,
298295 memcpy (buf + nchars * sizeof (*dst), &last, sizeof (last));
299296 nchars++;
300297
301- *chars_written = nchars;
302298 return nchars * sizeof (*dst);
303299}
304300
305-
306301size_t StringBytes::Write (Isolate* isolate,
307302 char * buf,
308303 size_t buflen,
309304 Local<Value> val,
310- enum encoding encoding,
311- int * chars_written) {
305+ enum encoding encoding) {
312306 HandleScope scope (isolate);
313307 size_t nbytes;
314- int nchars;
315-
316- if (chars_written == nullptr )
317- chars_written = &nchars;
318308
319309 CHECK (val->IsString () == true );
320310 Local<String> str = val.As <String>();
@@ -334,19 +324,15 @@ size_t StringBytes::Write(Isolate* isolate,
334324 uint8_t * const dst = reinterpret_cast <uint8_t *>(buf);
335325 nbytes = str->WriteOneByte (isolate, dst, 0 , buflen, flags);
336326 }
337- *chars_written = nbytes;
338327 break ;
339328
340329 case BUFFER:
341330 case UTF8:
342- nbytes = str->WriteUtf8 (isolate, buf, buflen, chars_written , flags);
331+ nbytes = str->WriteUtf8 (isolate, buf, buflen, nullptr , flags);
343332 break ;
344333
345334 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);
350336
351337 // Node's "ucs2" encoding wants LE character data stored in
352338 // the Buffer, so we need to reorder on BE platforms. See
@@ -368,7 +354,6 @@ size_t StringBytes::Write(Isolate* isolate,
368354 String::Value value (isolate, str);
369355 nbytes = base64_decode (buf, buflen, *value, value.length ());
370356 }
371- *chars_written = nbytes;
372357 break ;
373358
374359 case HEX:
@@ -379,7 +364,6 @@ size_t StringBytes::Write(Isolate* isolate,
379364 String::Value value (isolate, str);
380365 nbytes = hex_decode (buf, buflen, *value, value.length ());
381366 }
382- *chars_written = nbytes;
383367 break ;
384368
385369 default :
@@ -390,7 +374,6 @@ size_t StringBytes::Write(Isolate* isolate,
390374 return nbytes;
391375}
392376
393-
394377// Quick and dirty size calculation
395378// Will always be at least big enough, but may have some extra
396379// UTF8 can be as much as 3x the size, Base64 can have 1-2 extra bytes
0 commit comments