diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-15 16:26:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 15:26:10 +0000 |
commit | 585ec1218f8cdc191f2e733beb2e6c7a230ac85c (patch) | |
tree | 8a0e5d88f2390890121a6083a39c833af21ea5d1 /ext | |
parent | 0d4e4af7acf82c1365999a7281910daa05f0e982 (diff) |
Revert "feat(ops): Fast zero copy string arguments (#16777)" (#17063)
This reverts commit 9b2b8df927ac23cfa99016a684179f2a3198ba2e.
Closes https://github.com/dsherret/ts-morph/issues/1372
Closes https://github.com/denoland/deno/issues/16979
Diffstat (limited to 'ext')
-rw-r--r-- | ext/node/lib.rs | 2 | ||||
-rw-r--r-- | ext/url/00_url.js | 8 | ||||
-rw-r--r-- | ext/url/lib.rs | 19 | ||||
-rw-r--r-- | ext/web/blob.rs | 4 | ||||
-rw-r--r-- | ext/web/compression.rs | 4 | ||||
-rw-r--r-- | ext/web/lib.rs | 52 | ||||
-rw-r--r-- | ext/webstorage/lib.rs | 6 |
7 files changed, 39 insertions, 56 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 5282c0660..b2443db0b 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -262,7 +262,7 @@ fn op_require_proxy_path(filename: String) -> String { } #[op] -fn op_require_is_request_relative(request: &str) -> bool { +fn op_require_is_request_relative(request: String) -> bool { if request.starts_with("./") || request.starts_with("../") || request == ".." { return true; diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 754c647b1..5479cb59c 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -56,12 +56,12 @@ function opUrlParse(href, maybeBase) { let status; if (maybeBase === undefined) { - status = ops.op_url_parse(href, componentsBuf); + status = ops.op_url_parse(href, componentsBuf.buffer); } else { - status = ops.op_url_parse_with_base( + status = core.ops.op_url_parse_with_base( href, maybeBase, - componentsBuf, + componentsBuf.buffer, ); } return getSerialization(status, href); @@ -71,7 +71,7 @@ if (status === 0) { return href; } else if (status === 1) { - return ops.op_url_get_serialization(); + return core.ops.op_url_get_serialization(); } else { throw new TypeError("Invalid URL"); } diff --git a/ext/url/lib.rs b/ext/url/lib.rs index 01014ccd3..ac668207f 100644 --- a/ext/url/lib.rs +++ b/ext/url/lib.rs @@ -41,11 +41,11 @@ pub fn init() -> Extension { #[op] pub fn op_url_parse_with_base( state: &mut OpState, - href: &str, - base_href: &str, - buf: &mut [u32], + href: String, + base_href: String, + buf: &mut [u8], ) -> u32 { - let base_url = match Url::parse(base_href) { + let base_url = match Url::parse(&base_href) { Ok(url) => url, Err(_) => return ParseStatus::Err as u32, }; @@ -67,8 +67,8 @@ pub fn op_url_get_serialization(state: &mut OpState) -> String { } /// Parse `href` without a `base_url`. Fills the out `buf` with URL components. -#[op(fast)] -pub fn op_url_parse(state: &mut OpState, href: &str, buf: &mut [u32]) -> u32 { +#[op] +pub fn op_url_parse(state: &mut OpState, href: String, buf: &mut [u8]) -> u32 { parse_url(state, href, None, buf) } @@ -99,14 +99,15 @@ pub fn op_url_parse(state: &mut OpState, href: &str, buf: &mut [u32]) -> u32 { #[inline] fn parse_url( state: &mut OpState, - href: &str, + href: String, base_href: Option<&Url>, - buf: &mut [u32], + buf: &mut [u8], ) -> u32 { - match Url::options().base_url(base_href).parse(href) { + match Url::options().base_url(base_href).parse(&href) { Ok(url) => { let inner_url = quirks::internal_components(&url); + let buf: &mut [u32] = as_u32_slice(buf); buf[0] = inner_url.scheme_end; buf[1] = inner_url.username_end; buf[2] = inner_url.host_start; diff --git a/ext/web/blob.rs b/ext/web/blob.rs index 5f1936860..7da42e178 100644 --- a/ext/web/blob.rs +++ b/ext/web/blob.rs @@ -252,9 +252,9 @@ pub fn op_blob_create_object_url( #[op] pub fn op_blob_revoke_object_url( state: &mut deno_core::OpState, - url: &str, + url: String, ) -> Result<(), AnyError> { - let url = Url::parse(url)?; + let url = Url::parse(&url)?; let blob_store = state.borrow::<BlobStore>(); blob_store.remove_object_url(&url); Ok(()) diff --git a/ext/web/compression.rs b/ext/web/compression.rs index 05dcf02b1..d2647e498 100644 --- a/ext/web/compression.rs +++ b/ext/web/compression.rs @@ -41,11 +41,11 @@ impl Resource for CompressionResource { #[op] pub fn op_compression_new( state: &mut OpState, - format: &str, + format: String, is_decoder: bool, ) -> ResourceId { let w = Vec::new(); - let inner = match (format, is_decoder) { + let inner = match (format.as_str(), is_decoder) { ("deflate", true) => Inner::DeflateDecoder(ZlibDecoder::new(w)), ("deflate", false) => { Inner::DeflateEncoder(ZlibEncoder::new(w, Compression::default())) diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 7c75a9a28..cfbcee6e3 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -270,7 +270,7 @@ fn op_encoding_decode_single( #[op] fn op_encoding_new_decoder( state: &mut OpState, - label: &str, + label: String, fatal: bool, ignore_bom: bool, ) -> Result<ResourceId, AnyError> { @@ -352,43 +352,25 @@ impl Resource for TextDecoderResource { } } -#[op] +#[op(v8)] fn op_encoding_encode_into( - input: Cow<'_, str>, + scope: &mut v8::HandleScope, + input: serde_v8::Value, buffer: &mut [u8], out_buf: &mut [u32], -) { - // Since `input` is already UTF-8, we can simply find the last UTF-8 code - // point boundary from input that fits in `buffer`, and copy the bytes up to - // that point. - let boundary = if buffer.len() >= input.len() { - input.len() - } else { - let mut boundary = buffer.len(); - - // The maximum length of a UTF-8 code point is 4 bytes. - for _ in 0..4 { - if input.is_char_boundary(boundary) { - break; - } - debug_assert!(boundary > 0); - boundary -= 1; - } - - debug_assert!(input.is_char_boundary(boundary)); - boundary - }; - - buffer[..boundary].copy_from_slice(input[..boundary].as_bytes()); - - // The `read` output parameter is measured in UTF-16 code units. - out_buf[0] = match input { - // Borrowed Cow strings are zero-copy views into the V8 heap. - // Thus, they are guarantee to be SeqOneByteString. - Cow::Borrowed(v) => v[..boundary].len() as u32, - Cow::Owned(v) => v[..boundary].encode_utf16().count() as u32, - }; - out_buf[1] = boundary as u32; +) -> Result<(), AnyError> { + let s = v8::Local::<v8::String>::try_from(input.v8_value)?; + + let mut nchars = 0; + out_buf[1] = s.write_utf8( + scope, + buffer, + Some(&mut nchars), + v8::WriteOptions::NO_NULL_TERMINATION + | v8::WriteOptions::REPLACE_INVALID_UTF8, + ) as u32; + out_buf[0] = nchars as u32; + Ok(()) } #[op(v8)] diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 58b7c07e4..6284a59bc 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -139,8 +139,8 @@ pub fn op_webstorage_key( #[op] pub fn op_webstorage_set( state: &mut OpState, - key: &str, - value: &str, + key: String, + value: String, persistent: bool, ) -> Result<(), AnyError> { let conn = get_webstorage(state, persistent)?; @@ -184,7 +184,7 @@ pub fn op_webstorage_get( #[op] pub fn op_webstorage_remove( state: &mut OpState, - key_name: &str, + key_name: String, persistent: bool, ) -> Result<(), AnyError> { let conn = get_webstorage(state, persistent)?; |