diff --git a/Cargo.lock b/Cargo.lock index d91d84fa0a8..c5f93c9eb70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,7 @@ dependencies = [ "boa_string", "bytemuck", "cfg-if", + "cow-utils", "criterion", "dashmap", "either", @@ -921,6 +922,12 @@ dependencies = [ "libm", ] +[[package]] +name = "cow-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" + [[package]] name = "crc32fast" version = "1.4.2" diff --git a/Cargo.toml b/Cargo.toml index b411f795297..4622de3ae10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ arbitrary = "1" bitflags = "2.5.0" clap = "4.5.23" colored = "2.2.0" +cow-utils = "0.1.3" fast-float2 = "0.2.3" hashbrown = "0.15.2" indexmap = { version = "2.7.0", default-features = false } diff --git a/clippy.toml b/clippy.toml index 272425dad89..59ef99e1fe1 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,2 +1,5 @@ doc-valid-idents = ['ECMAScript', 'JavaScript', 'SpiderMonkey', 'GitHub'] allow-print-in-tests = true +disallowed-methods = [ + { path = "str::to_ascii_uppercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_ascii_uppercase` instead." }, +] diff --git a/core/engine/Cargo.toml b/core/engine/Cargo.toml index 9a0d603e427..e6b225ebadf 100644 --- a/core/engine/Cargo.toml +++ b/core/engine/Cargo.toml @@ -75,6 +75,7 @@ boa_macros.workspace = true boa_ast.workspace = true boa_parser.workspace = true boa_string.workspace = true +cow-utils.workspace = true serde = { workspace = true, features = ["derive", "rc"] } serde_json.workspace = true rand.workspace = true diff --git a/core/engine/src/builtins/temporal/time_zone/mod.rs b/core/engine/src/builtins/temporal/time_zone/mod.rs index a1d499e5829..2e73f0a2e0c 100644 --- a/core/engine/src/builtins/temporal/time_zone/mod.rs +++ b/core/engine/src/builtins/temporal/time_zone/mod.rs @@ -2,7 +2,7 @@ #![allow(dead_code)] use crate::{builtins::temporal::to_zero_padded_decimal_string, Context}; - +use cow_utils::CowUtils; // -- TimeZone Abstract Operations -- /// Abstract operation `DefaultTimeZone ( )` @@ -96,7 +96,7 @@ fn canonicalize_time_zone_name(time_zone: &str) -> String { // do not include local political rules for any time zones performs the following steps when // called: // 1. Assert: timeZone is an ASCII-case-insensitive match for "UTC". - assert_eq!(time_zone.to_ascii_uppercase(), "UTC"); + assert_eq!(time_zone.cow_to_ascii_uppercase(), "UTC"); // 2. Return "UTC". "UTC".to_owned() }