Skip to content

Commit

Permalink
templater: clone WorkspaceId/OperationId into templater to simplify l…
Browse files Browse the repository at this point in the history
…ifetime

There would be no measurable cost to clone a couple of id objects.
  • Loading branch information
yuja committed Feb 25, 2024
1 parent 79f86fb commit 3f07fa3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ use crate::templater::{
};
use crate::text_util;

struct CommitTemplateLanguage<'repo, 'b> {
struct CommitTemplateLanguage<'repo> {
repo: &'repo dyn Repo,
workspace_id: &'b WorkspaceId,
workspace_id: WorkspaceId,
id_prefix_context: &'repo IdPrefixContext,
build_fn_table: CommitTemplateBuildFnTable<'repo>,
keyword_cache: CommitKeywordCache,
}

impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo, '_> {
impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> {
type Context = Commit;
type Property = CommitTemplatePropertyKind<'repo>;

Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo, '_> {

// If we need to add multiple languages that support Commit types, this can be
// turned into a trait which extends TemplateLanguage.
impl<'repo> CommitTemplateLanguage<'repo, '_> {
impl<'repo> CommitTemplateLanguage<'repo> {
fn wrap_commit(
&self,
property: impl TemplateProperty<Commit, Output = Commit> + 'repo,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<'repo> IntoTemplateProperty<'repo, Commit> for CommitTemplatePropertyKind<'
// table is bound to a named lifetime, and therefore can't be cached statically.
type CommitTemplateBuildMethodFn<'repo, T> =
fn(
&CommitTemplateLanguage<'repo, '_>,
&CommitTemplateLanguage<'repo>,
&BuildContext<CommitTemplatePropertyKind<'repo>>,
Box<dyn TemplateProperty<Commit, Output = T> + 'repo>,
&FunctionCallNode,
Expand Down Expand Up @@ -546,7 +546,7 @@ impl Template<()> for Vec<RefName> {
}

fn build_ref_name_method<'repo>(
language: &CommitTemplateLanguage<'repo, '_>,
language: &CommitTemplateLanguage<'repo>,
_build_ctx: &BuildContext<CommitTemplatePropertyKind<'repo>>,
self_property: impl TemplateProperty<Commit, Output = RefName> + 'repo,
function: &FunctionCallNode,
Expand Down Expand Up @@ -704,7 +704,7 @@ impl Template<()> for CommitOrChangeId {
}

fn build_commit_or_change_id_method<'repo>(
language: &CommitTemplateLanguage<'repo, '_>,
language: &CommitTemplateLanguage<'repo>,
build_ctx: &BuildContext<CommitTemplatePropertyKind<'repo>>,
self_property: impl TemplateProperty<Commit, Output = CommitOrChangeId> + 'repo,
function: &FunctionCallNode,
Expand Down Expand Up @@ -775,7 +775,7 @@ impl ShortestIdPrefix {
}

fn build_shortest_id_prefix_method<'repo>(
language: &CommitTemplateLanguage<'repo, '_>,
language: &CommitTemplateLanguage<'repo>,
_build_ctx: &BuildContext<CommitTemplatePropertyKind<'repo>>,
self_property: impl TemplateProperty<Commit, Output = ShortestIdPrefix> + 'repo,
function: &FunctionCallNode,
Expand Down Expand Up @@ -818,7 +818,7 @@ pub fn parse<'repo>(
) -> TemplateParseResult<Box<dyn Template<Commit> + 'repo>> {
let language = CommitTemplateLanguage {
repo,
workspace_id,
workspace_id: workspace_id.clone(),
id_prefix_context,
build_fn_table: CommitTemplateBuildFnTable::builtin(),
keyword_cache: CommitKeywordCache::default(),
Expand Down
16 changes: 8 additions & 8 deletions cli/src/operation_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ use crate::templater::{
TemplatePropertyFn, TimestampRange,
};

struct OperationTemplateLanguage<'b> {
root_op_id: &'b OperationId,
current_op_id: Option<&'b OperationId>,
struct OperationTemplateLanguage {
root_op_id: OperationId,
current_op_id: Option<OperationId>,
}

impl TemplateLanguage<'static> for OperationTemplateLanguage<'_> {
impl TemplateLanguage<'static> for OperationTemplateLanguage {
type Context = Operation;
type Property = OperationTemplatePropertyKind;

Expand Down Expand Up @@ -67,7 +67,7 @@ impl TemplateLanguage<'static> for OperationTemplateLanguage<'_> {
}
}

impl OperationTemplateLanguage<'_> {
impl OperationTemplateLanguage {
fn wrap_operation(
&self,
property: impl TemplateProperty<Operation, Output = Operation> + 'static,
Expand Down Expand Up @@ -133,7 +133,7 @@ fn build_operation_method(
let property = match function.name {
"current_operation" => {
template_parser::expect_no_arguments(function)?;
let current_op_id = language.current_op_id.cloned();
let current_op_id = language.current_op_id.clone();
language.wrap_boolean(TemplateFunction::new(self_property, move |op| {
Some(op.id()) == current_op_id.as_ref()
}))
Expand Down Expand Up @@ -226,8 +226,8 @@ pub fn parse(
aliases_map: &TemplateAliasesMap,
) -> TemplateParseResult<Box<dyn Template<Operation>>> {
let language = OperationTemplateLanguage {
root_op_id,
current_op_id,
root_op_id: root_op_id.clone(),
current_op_id: current_op_id.cloned(),
};
let node = template_parser::parse(template_text, aliases_map)?;
template_builder::build(&language, &node)
Expand Down

0 comments on commit 3f07fa3

Please sign in to comment.