mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
perf(ext/web): flatten op arguments for text_encoding (#15723)
This commit is contained in:
parent
73b4597dec
commit
0abf5a412b
2 changed files with 20 additions and 47 deletions
|
@ -125,24 +125,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.stream && this.#rid === null) {
|
if (!options.stream && this.#rid === null) {
|
||||||
return ops.op_encoding_decode_single(input, {
|
return ops.op_encoding_decode_single(
|
||||||
label: this.#encoding,
|
input,
|
||||||
fatal: this.#fatal,
|
this.#encoding,
|
||||||
ignoreBom: this.#ignoreBOM,
|
this.#fatal,
|
||||||
});
|
this.#ignoreBOM,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#rid === null) {
|
if (this.#rid === null) {
|
||||||
this.#rid = ops.op_encoding_new_decoder({
|
this.#rid = ops.op_encoding_new_decoder(
|
||||||
label: this.#encoding,
|
this.#encoding,
|
||||||
fatal: this.#fatal,
|
this.#fatal,
|
||||||
ignoreBom: this.#ignoreBOM,
|
this.#ignoreBOM,
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
return ops.op_encoding_decode(input, {
|
return ops.op_encoding_decode(input, this.#rid, options.stream);
|
||||||
rid: this.#rid,
|
|
||||||
stream: options.stream,
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
if (!options.stream && this.#rid !== null) {
|
if (!options.stream && this.#rid !== null) {
|
||||||
core.close(this.#rid);
|
core.close(this.#rid);
|
||||||
|
|
|
@ -23,7 +23,6 @@ use encoding_rs::CoderResult;
|
||||||
use encoding_rs::Decoder;
|
use encoding_rs::Decoder;
|
||||||
use encoding_rs::DecoderResult;
|
use encoding_rs::DecoderResult;
|
||||||
use encoding_rs::Encoding;
|
use encoding_rs::Encoding;
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -166,14 +165,6 @@ fn forgiving_base64_encode(s: &[u8]) -> String {
|
||||||
BASE64_STANDARD.encode_to_boxed_str(s).into_string()
|
BASE64_STANDARD.encode_to_boxed_str(s).into_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct DecoderOptions {
|
|
||||||
label: String,
|
|
||||||
ignore_bom: bool,
|
|
||||||
fatal: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_normalize_label(label: String) -> Result<String, AnyError> {
|
fn op_encoding_normalize_label(label: String) -> Result<String, AnyError> {
|
||||||
let encoding = Encoding::for_label_no_replacement(label.as_bytes())
|
let encoding = Encoding::for_label_no_replacement(label.as_bytes())
|
||||||
|
@ -189,14 +180,10 @@ fn op_encoding_normalize_label(label: String) -> Result<String, AnyError> {
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_decode_single(
|
fn op_encoding_decode_single(
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
options: DecoderOptions,
|
label: String,
|
||||||
|
fatal: bool,
|
||||||
|
ignore_bom: bool,
|
||||||
) -> Result<U16String, AnyError> {
|
) -> Result<U16String, AnyError> {
|
||||||
let DecoderOptions {
|
|
||||||
label,
|
|
||||||
ignore_bom,
|
|
||||||
fatal,
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
let encoding = Encoding::for_label(label.as_bytes()).ok_or_else(|| {
|
let encoding = Encoding::for_label(label.as_bytes()).ok_or_else(|| {
|
||||||
range_error(format!(
|
range_error(format!(
|
||||||
"The encoding label provided ('{}') is invalid.",
|
"The encoding label provided ('{}') is invalid.",
|
||||||
|
@ -247,14 +234,10 @@ fn op_encoding_decode_single(
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_new_decoder(
|
fn op_encoding_new_decoder(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
options: DecoderOptions,
|
label: String,
|
||||||
|
fatal: bool,
|
||||||
|
ignore_bom: bool,
|
||||||
) -> Result<ResourceId, AnyError> {
|
) -> Result<ResourceId, AnyError> {
|
||||||
let DecoderOptions {
|
|
||||||
label,
|
|
||||||
fatal,
|
|
||||||
ignore_bom,
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
let encoding = Encoding::for_label(label.as_bytes()).ok_or_else(|| {
|
let encoding = Encoding::for_label(label.as_bytes()).ok_or_else(|| {
|
||||||
range_error(format!(
|
range_error(format!(
|
||||||
"The encoding label provided ('{}') is invalid.",
|
"The encoding label provided ('{}') is invalid.",
|
||||||
|
@ -276,21 +259,13 @@ fn op_encoding_new_decoder(
|
||||||
Ok(rid)
|
Ok(rid)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct DecodeOptions {
|
|
||||||
rid: ResourceId,
|
|
||||||
stream: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_decode(
|
fn op_encoding_decode(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
options: DecodeOptions,
|
rid: ResourceId,
|
||||||
|
stream: bool,
|
||||||
) -> Result<U16String, AnyError> {
|
) -> Result<U16String, AnyError> {
|
||||||
let DecodeOptions { rid, stream } = options;
|
|
||||||
|
|
||||||
let resource = state.resource_table.get::<TextDecoderResource>(rid)?;
|
let resource = state.resource_table.get::<TextDecoderResource>(rid)?;
|
||||||
|
|
||||||
let mut decoder = resource.decoder.borrow_mut();
|
let mut decoder = resource.decoder.borrow_mut();
|
||||||
|
|
Loading…
Add table
Reference in a new issue