From 5bd31c713ac37e175e6c0e68c443cd7aad7dbba0 Mon Sep 17 00:00:00 2001 From: shulaoda Date: Wed, 9 Oct 2024 07:22:45 +0800 Subject: [PATCH] solve conflicts --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + crates/rspack_core/Cargo.toml | 1 + crates/rspack_core/src/utils/runtime.rs | 9 ++++++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f75367fc606..c5c7236485b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -674,6 +674,12 @@ dependencies = [ "windows-sys 0.33.0", ] +[[package]] +name = "cow-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" + [[package]] name = "cpufeatures" version = "0.2.9" @@ -3433,6 +3439,7 @@ dependencies = [ "async-recursion", "async-trait", "bitflags 2.5.0", + "cow-utils", "dashmap 5.5.3", "derivative", "dyn-clone", diff --git a/Cargo.toml b/Cargo.toml index a061c41f592..c643b87415e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ async-trait = { version = "0.1.79" } bitflags = { version = "2.5.0" } camino = { version = "1.1.8" } concat-string = { version = "1.0.1" } +cow-utils = { version = "0.1.3" } css-module-lexer = { version = "0.0.14" } dashmap = { version = "5.5.3" } derivative = { version = "2.2.0" } diff --git a/crates/rspack_core/Cargo.toml b/crates/rspack_core/Cargo.toml index 3d71e4ff397..ffd45eb7683 100644 --- a/crates/rspack_core/Cargo.toml +++ b/crates/rspack_core/Cargo.toml @@ -10,6 +10,7 @@ anymap = { workspace = true } async-recursion = { workspace = true } async-trait = { workspace = true } bitflags = { workspace = true } +cow-utils = { workspace = true } dashmap = { workspace = true, features = ["rayon"] } derivative = { workspace = true } dyn-clone = "1.0.17" diff --git a/crates/rspack_core/src/utils/runtime.rs b/crates/rspack_core/src/utils/runtime.rs index d9d9c8354e7..eda7d8f06dd 100644 --- a/crates/rspack_core/src/utils/runtime.rs +++ b/crates/rspack_core/src/utils/runtime.rs @@ -1,3 +1,6 @@ +use std::borrow::Cow; + +use cow_utils::CowUtils; use indexmap::IndexMap; use rustc_hash::FxHashMap as HashMap; use rustc_hash::FxHashSet as HashSet; @@ -130,7 +133,7 @@ pub fn get_filename_without_hash_length( let Some(template) = filename.template() else { return (filename.clone(), hash_len_map); }; - let mut template = template.to_string(); + let mut template = Cow::Borrowed(template); for key in [ HASH_PLACEHOLDER, FULL_HASH_PLACEHOLDER, @@ -141,8 +144,8 @@ pub fn get_filename_without_hash_length( if let Some(hash_len) = p.len { hash_len_map.insert((*key).to_string(), hash_len); } - template = template.replace(&p.pattern, key); + template = Cow::Owned(template.cow_replace(&p.pattern, key).into_owned()); } } - (Filename::from(template), hash_len_map) + (Filename::from(template.into_owned()), hash_len_map) }