Skip to content

Commit f266cc1

Browse files
committed
Revert "util: add fast path for Latin1 decoding"
This reverts commit 20bcaa0.
1 parent d1ab5ef commit f266cc1

File tree

4 files changed

+2
-60
lines changed

4 files changed

+2
-60
lines changed

benchmark/util/text-decoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../common.js');
44

55
const bench = common.createBenchmark(main, {
6-
encoding: ['utf-8', 'windows-1252', 'iso-8859-3'],
6+
encoding: ['utf-8', 'latin1', 'iso-8859-3'],
77
ignoreBOM: [0, 1],
88
fatal: [0, 1],
99
len: [256, 1024 * 16, 1024 * 128],

lib/internal/encoding.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const kEncoding = Symbol('encoding');
2828
const kDecoder = Symbol('decoder');
2929
const kFatal = Symbol('kFatal');
3030
const kUTF8FastPath = Symbol('kUTF8FastPath');
31-
const kLatin1FastPath = Symbol('kLatin1FastPath');
3231
const kIgnoreBOM = Symbol('kIgnoreBOM');
3332

3433
const {
@@ -55,7 +54,6 @@ const {
5554
encodeIntoResults,
5655
encodeUtf8String,
5756
decodeUTF8,
58-
decodeLatin1,
5957
} = binding;
6058

6159
const { Buffer } = require('buffer');
@@ -420,10 +418,9 @@ function makeTextDecoderICU() {
420418
this[kFatal] = Boolean(options?.fatal);
421419
// Only support fast path for UTF-8.
422420
this[kUTF8FastPath] = enc === 'utf-8';
423-
this[kLatin1FastPath] = enc === 'windows-1252';
424421
this[kHandle] = undefined;
425422

426-
if (!this[kUTF8FastPath] && !this[kLatin1FastPath]) {
423+
if (!this[kUTF8FastPath]) {
427424
this.#prepareConverter();
428425
}
429426
}
@@ -440,16 +437,11 @@ function makeTextDecoderICU() {
440437
validateDecoder(this);
441438

442439
this[kUTF8FastPath] &&= !(options?.stream);
443-
this[kLatin1FastPath] &&= !(options?.stream);
444440

445441
if (this[kUTF8FastPath]) {
446442
return decodeUTF8(input, this[kIgnoreBOM], this[kFatal]);
447443
}
448444

449-
if (this[kLatin1FastPath]) {
450-
return decodeLatin1(input, this[kIgnoreBOM], this[kFatal]);
451-
}
452-
453445
this.#prepareConverter();
454446

455447
validateObject(options, 'options', kValidateObjectAllowObjectsAndNull);

src/encoding_binding.cc

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "encoding_binding.h"
22
#include "ada.h"
33
#include "env-inl.h"
4-
#include "node_buffer.h"
54
#include "node_errors.h"
65
#include "node_external_reference.h"
76
#include "simdutf.h"
@@ -221,7 +220,6 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
221220
SetMethodNoSideEffect(isolate, target, "decodeUTF8", DecodeUTF8);
222221
SetMethodNoSideEffect(isolate, target, "toASCII", ToASCII);
223222
SetMethodNoSideEffect(isolate, target, "toUnicode", ToUnicode);
224-
SetMethodNoSideEffect(isolate, target, "decodeLatin1", DecodeLatin1);
225223
}
226224

227225
void BindingData::CreatePerContextProperties(Local<Object> target,
@@ -239,53 +237,6 @@ void BindingData::RegisterTimerExternalReferences(
239237
registry->Register(DecodeUTF8);
240238
registry->Register(ToASCII);
241239
registry->Register(ToUnicode);
242-
registry->Register(DecodeLatin1);
243-
}
244-
245-
void BindingData::DecodeLatin1(const FunctionCallbackInfo<Value>& args) {
246-
Environment* env = Environment::GetCurrent(args);
247-
248-
CHECK_GE(args.Length(), 1);
249-
if (!(args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer() ||
250-
args[0]->IsArrayBufferView())) {
251-
return node::THROW_ERR_INVALID_ARG_TYPE(
252-
env->isolate(),
253-
"The \"input\" argument must be an instance of ArrayBuffer, "
254-
"SharedArrayBuffer, or ArrayBufferView.");
255-
}
256-
257-
bool ignore_bom = args[1]->IsTrue();
258-
bool has_fatal = args[2]->IsTrue();
259-
260-
ArrayBufferViewContents<uint8_t> buffer(args[0]);
261-
const uint8_t* data = buffer.data();
262-
size_t length = buffer.length();
263-
264-
if (ignore_bom && length > 0 && data[0] == 0xFF) {
265-
data++;
266-
length--;
267-
}
268-
269-
if (length == 0) {
270-
return args.GetReturnValue().SetEmptyString();
271-
}
272-
273-
std::string result(length * 2, '\0');
274-
275-
size_t written = simdutf::convert_latin1_to_utf8(
276-
reinterpret_cast<const char*>(data), length, result.data());
277-
278-
if (has_fatal && written == 0) {
279-
return node::THROW_ERR_ENCODING_INVALID_ENCODED_DATA(
280-
env->isolate(), "The encoded data was not valid for encoding latin1");
281-
}
282-
283-
std::string_view view(result.c_str(), written);
284-
285-
Local<Value> ret;
286-
if (ToV8Value(env->context(), view, env->isolate()).ToLocal(&ret)) {
287-
args.GetReturnValue().Set(ret);
288-
}
289240
}
290241

291242
} // namespace encoding_binding

src/encoding_binding.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class BindingData : public SnapshotableObject {
3131
static void EncodeInto(const v8::FunctionCallbackInfo<v8::Value>& args);
3232
static void EncodeUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
3333
static void DecodeUTF8(const v8::FunctionCallbackInfo<v8::Value>& args);
34-
static void DecodeLatin1(const v8::FunctionCallbackInfo<v8::Value>& args);
3534

3635
static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
3736
static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
 (0)