From e4176937f0584a6bcc5aba15abb1e2df6ddf588d Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 5 May 2023 19:37:40 +0000 Subject: remove more unnecessary brigadier cloning! --- azalea-brigadier/src/command_dispatcher.rs | 36 ++++++++---------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'azalea-brigadier/src/command_dispatcher.rs') diff --git a/azalea-brigadier/src/command_dispatcher.rs b/azalea-brigadier/src/command_dispatcher.rs index ba41223e..29fadfd1 100755 --- a/azalea-brigadier/src/command_dispatcher.rs +++ b/azalea-brigadier/src/command_dispatcher.rs @@ -10,12 +10,12 @@ use std::{cell::RefCell, cmp::Ordering, collections::HashMap, marker::PhantomDat /// The root of the command tree. You need to make this to register commands. #[derive(Default)] -pub struct CommandDispatcher { +pub struct CommandDispatcher<'a, S> { pub root: Rc>>, - _marker: PhantomData, + _marker: PhantomData<(S, &'a ())>, } -impl CommandDispatcher { +impl<'a, S> CommandDispatcher<'a, S> { pub fn new() -> Self { Self { root: Rc::new(RefCell::new(CommandNode::default())), @@ -30,21 +30,16 @@ impl CommandDispatcher { } pub fn parse(&self, command: StringReader, source: Rc) -> ParseResults { - let context = CommandContextBuilder::new( - Rc::new(self.clone()), - source, - self.root.clone(), - command.cursor(), - ); + let context = CommandContextBuilder::new(self, source, self.root.clone(), command.cursor()); self.parse_nodes(&self.root, &command, context).unwrap() } fn parse_nodes( - &self, + &'a self, node: &Rc>>, original_reader: &StringReader, - context_so_far: CommandContextBuilder, - ) -> Result, CommandSyntaxException> { + context_so_far: CommandContextBuilder<'a, S>, + ) -> Result, CommandSyntaxException> { let source = context_so_far.source.clone(); let mut errors = HashMap::>, CommandSyntaxException>::new(); let mut potentials: Vec> = vec![]; @@ -91,12 +86,8 @@ impl CommandDispatcher { }) { reader.skip(); if let Some(redirect) = &child.borrow().redirect { - let child_context = CommandContextBuilder::new( - Rc::new(self.clone()), - source, - redirect.clone(), - reader.cursor, - ); + let child_context = + CommandContextBuilder::new(self, source, redirect.clone(), reader.cursor); let parse = self .parse_nodes(redirect, &reader, child_context) .expect("Parsing nodes failed"); @@ -287,12 +278,3 @@ impl CommandDispatcher { // Ok(if forked { successful_forks } else { result }) } } - -impl Clone for CommandDispatcher { - fn clone(&self) -> Self { - Self { - root: self.root.clone(), - _marker: PhantomData, - } - } -} -- cgit v1.2.3