File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,8 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
380380 }
381381}
382382
383+ static uint32_t * tWindows1252x2 = 0 ;
384+
383385void BindingData::DecodeSingleByte (const FunctionCallbackInfo<Value>& args) {
384386 Environment* env = Environment::GetCurrent (args);
385387
@@ -416,6 +418,26 @@ void BindingData::DecodeSingleByte(const FunctionCallbackInfo<Value>& args) {
416418 if (encoding == 28 ) {
417419 // x-user-defined
418420 for (size_t i = 0 ; i < length; i++) dst[i] = data[i] >= 0x80 ? data[i] + 0xf700 : data[i];
421+ } else if (encoding == 21 && (tWindows1252x2 || length > 256 * 256 ) && ((size_t ) data) % 2 == 0 ) {
422+ // TODO(chalker): remove alignment check and align
423+
424+ const uint16_t * table = tSingleByteEncodings[encoding];
425+ if (!tWindows1252x2) {
426+ tWindows1252x2 = (uint32_t *) malloc (256 * 256 * 4 ); // 256 KiB
427+ for (uint16_t i = 0 ; i < 256 ; i++) {
428+ for (uint16_t j = 0 ; j < 256 ; j++) {
429+ tWindows1252x2[(i << 8 ) + j] = (((uint32_t ) table[i]) << 16 ) + table[j];
430+ }
431+ }
432+ }
433+
434+ size_t length2 = length / 2 ;
435+ size_t i = 0 ;
436+ const uint16_t * data2 = reinterpret_cast <const uint16_t *>(data);
437+ uint32_t * dst2 = reinterpret_cast <uint32_t *>(dst);
438+ for (; i < length2; i++) dst2[i] = tWindows1252x2[data2[i]];
439+ i *= 2 ;
440+ for (; i < length; i++) dst[i] = table[data[i]];
419441 } else {
420442 bool has_fatal = args[2 ]->IsTrue ();
421443
You can’t perform that action at this time.
0 commit comments