@@ -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
0 commit comments