Skip to content

Commit

Permalink
Remove Arc<String> usage again from next-custom-transform
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Nov 15, 2024
1 parent f2052a4 commit acdafab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::server_actions::{server_actions, Config};
Expand Down Expand Up @@ -59,7 +57,7 @@ impl CustomTransformer for NextServerActions {
.cache_kinds
.await?
.iter()
.map(|cache_kind| Arc::from(cache_kind.clone().into_owned()))
.map(|cache_kind| cache_kind.clone().into_owned())
.collect(),
},
ctx.comments.clone(),
Expand Down
21 changes: 10 additions & 11 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
collections::{BTreeMap, HashSet},
convert::{TryFrom, TryInto},
mem::take,
sync::Arc,
};

use hex::encode as hex_encode;
Expand Down Expand Up @@ -31,7 +30,7 @@ pub struct Config {
pub is_react_server_layer: bool,
pub dynamic_io_enabled: bool,
pub hash_salt: String,
pub cache_kinds: FxHashSet<Arc<String>>,
pub cache_kinds: FxHashSet<String>,
}

enum DirectiveLocation {
Expand Down Expand Up @@ -70,7 +69,7 @@ enum ServerActionsErrorKind {
},
UnknownCacheKind {
span: Span,
cache_kind: Arc<String>,
cache_kind: String,
},
UseCacheWithoutDynamicIO {
span: Span,
Expand All @@ -89,7 +88,7 @@ pub type ActionsMap = BTreeMap<String, String>;
// Directive-level information about a function body
struct BodyInfo {
is_action_fn: bool,
cache_kind: Option<Arc<String>>,
cache_kind: Option<String>,
}

#[tracing::instrument(level = tracing::Level::TRACE, skip_all)]
Expand Down Expand Up @@ -150,7 +149,7 @@ struct ServerActions<C: Comments> {

start_pos: BytePos,
in_action_file: bool,
file_cache_kind: Option<Arc<String>>,
file_cache_kind: Option<String>,
in_exported_expr: bool,
in_default_export_decl: bool,
in_callee: bool,
Expand Down Expand Up @@ -2370,7 +2369,7 @@ fn detect_similar_strings(a: &str, b: &str) -> bool {
fn remove_server_directive_index_in_module(
stmts: &mut Vec<ModuleItem>,
in_action_file: &mut bool,
file_cache_kind: &mut Option<Arc<String>>,
file_cache_kind: &mut Option<String>,
has_action: &mut bool,
has_cache: &mut bool,
config: &Config,
Expand Down Expand Up @@ -2407,11 +2406,11 @@ fn remove_server_directive_index_in_module(
}

if value == "use cache" {
*file_cache_kind = Some(Arc::new("default".into()));
*file_cache_kind = Some("default".into());
} else {
// Slice the value after "use cache: "
let cache_kind_str =
Arc::new(value.split_at("use cache: ".len()).1.into());
String::from(value.split_at("use cache: ".len()).1);

if !config.cache_kinds.contains(&cache_kind_str) {
emit_error(ServerActionsErrorKind::UnknownCacheKind {
Expand Down Expand Up @@ -2521,7 +2520,7 @@ fn has_body_directive(maybe_body: &Option<BlockStmt>) -> (bool, bool) {
fn remove_server_directive_index_in_fn(
stmts: &mut Vec<Stmt>,
is_action_fn: &mut bool,
cache_kind: &mut Option<Arc<String>>,
cache_kind: &mut Option<String>,
action_span: &mut Option<Span>,
config: &Config,
) {
Expand Down Expand Up @@ -2563,10 +2562,10 @@ fn remove_server_directive_index_in_fn(
}

if value == "use cache" {
*cache_kind = Some(Arc::new("default".into()));
*cache_kind = Some("default".into());
} else {
// Slice the value after "use cache: "
let cache_kind_str = Arc::new(value.split_at("use cache: ".len()).1.into());
let cache_kind_str = String::from(value.split_at("use cache: ".len()).1);

if !config.cache_kinds.contains(&cache_kind_str) {
emit_error(ServerActionsErrorKind::UnknownCacheKind {
Expand Down
4 changes: 2 additions & 2 deletions crates/next-custom-transforms/tests/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{iter::FromIterator, path::PathBuf, sync::Arc};
use std::{iter::FromIterator, path::PathBuf};

use next_custom_transforms::transforms::{
disallow_re_export_all_in_page::disallow_re_export_all_in_page,
Expand Down Expand Up @@ -286,7 +286,7 @@ fn use_cache_not_allowed(input: PathBuf) {
is_react_server_layer: true,
dynamic_io_enabled: false,
hash_salt: "".into(),
cache_kinds: FxHashSet::from_iter([Arc::new("x".into())]),
cache_kinds: FxHashSet::from_iter(["x".into()]),
},
tr.comments.as_ref().clone(),
),
Expand Down
3 changes: 1 addition & 2 deletions crates/next-custom-transforms/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
env::current_dir,
iter::FromIterator,
path::{Path, PathBuf},
sync::Arc,
};

use next_custom_transforms::transforms::{
Expand Down Expand Up @@ -419,7 +418,7 @@ fn server_actions_server_fixture(input: PathBuf) {
is_react_server_layer: true,
dynamic_io_enabled: true,
hash_salt: "".into(),
cache_kinds: FxHashSet::from_iter([Arc::new("x".into())]),
cache_kinds: FxHashSet::from_iter(["x".into()]),
},
_tr.comments.as_ref().clone(),
),
Expand Down

0 comments on commit acdafab

Please sign in to comment.