diff options
| author | mat <github@matdoes.dev> | 2023-05-05 19:37:40 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-05-05 19:37:40 +0000 |
| commit | e4176937f0584a6bcc5aba15abb1e2df6ddf588d (patch) | |
| tree | e6db91c492702a66ebe45bc66553f23a547bd93e /azalea-brigadier/src | |
| parent | df167a5a391ef2a9bf2290a24d99ef8f559d9084 (diff) | |
| download | azalea-drasl-e4176937f0584a6bcc5aba15abb1e2df6ddf588d.tar.xz | |
remove more unnecessary brigadier cloning!
Diffstat (limited to 'azalea-brigadier/src')
| -rwxr-xr-x | azalea-brigadier/src/command_dispatcher.rs | 36 | ||||
| -rwxr-xr-x | azalea-brigadier/src/context/command_context_builder.rs | 16 | ||||
| -rwxr-xr-x | azalea-brigadier/src/parse_results.rs | 6 |
3 files changed, 20 insertions, 38 deletions
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<S> { +pub struct CommandDispatcher<'a, S> { pub root: Rc<RefCell<CommandNode<S>>>, - _marker: PhantomData<S>, + _marker: PhantomData<(S, &'a ())>, } -impl<S> CommandDispatcher<S> { +impl<'a, S> CommandDispatcher<'a, S> { pub fn new() -> Self { Self { root: Rc::new(RefCell::new(CommandNode::default())), @@ -30,21 +30,16 @@ impl<S> CommandDispatcher<S> { } pub fn parse(&self, command: StringReader, source: Rc<S>) -> ParseResults<S> { - 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<RefCell<CommandNode<S>>>, original_reader: &StringReader, - context_so_far: CommandContextBuilder<S>, - ) -> Result<ParseResults<S>, CommandSyntaxException> { + context_so_far: CommandContextBuilder<'a, S>, + ) -> Result<ParseResults<'a, S>, CommandSyntaxException> { let source = context_so_far.source.clone(); let mut errors = HashMap::<Rc<CommandNode<S>>, CommandSyntaxException>::new(); let mut potentials: Vec<ParseResults<S>> = vec![]; @@ -91,12 +86,8 @@ impl<S> CommandDispatcher<S> { }) { 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<S> CommandDispatcher<S> { // Ok(if forked { successful_forks } else { result }) } } - -impl<S> Clone for CommandDispatcher<S> { - fn clone(&self) -> Self { - Self { - root: self.root.clone(), - _marker: PhantomData, - } - } -} diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs index 7516ab9e..b0677158 100755 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -9,20 +9,20 @@ use crate::{ }; use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; -pub struct CommandContextBuilder<S> { +pub struct CommandContextBuilder<'a, S> { pub arguments: HashMap<String, ParsedArgument>, pub root: Rc<RefCell<CommandNode<S>>>, pub nodes: Vec<ParsedCommandNode<S>>, - pub dispatcher: Rc<CommandDispatcher<S>>, + pub dispatcher: &'a CommandDispatcher<'a, S>, pub source: Rc<S>, pub command: Command<S>, - pub child: Option<Rc<CommandContextBuilder<S>>>, + pub child: Option<Rc<CommandContextBuilder<'a, S>>>, pub range: StringRange, pub modifier: Option<Rc<RedirectModifier<S>>>, pub forks: bool, } -impl<S> Clone for CommandContextBuilder<S> { +impl<S> Clone for CommandContextBuilder<'_, S> { fn clone(&self) -> Self { Self { arguments: self.arguments.clone(), @@ -39,9 +39,9 @@ impl<S> Clone for CommandContextBuilder<S> { } } -impl<S> CommandContextBuilder<S> { +impl<'a, S> CommandContextBuilder<'a, S> { pub fn new( - dispatcher: Rc<CommandDispatcher<S>>, + dispatcher: &'a CommandDispatcher<S>, source: Rc<S>, root_node: Rc<RefCell<CommandNode<S>>>, start: usize, @@ -64,7 +64,7 @@ impl<S> CommandContextBuilder<S> { self.command = command.clone(); self } - pub fn with_child(&mut self, child: Rc<CommandContextBuilder<S>>) -> &Self { + pub fn with_child(&mut self, child: Rc<CommandContextBuilder<'a, S>>) -> &Self { self.child = Some(child); self } @@ -99,7 +99,7 @@ impl<S> CommandContextBuilder<S> { } } -impl<S> Debug for CommandContextBuilder<S> { +impl<S> Debug for CommandContextBuilder<'_, S> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("CommandContextBuilder") // .field("arguments", &self.arguments) diff --git a/azalea-brigadier/src/parse_results.rs b/azalea-brigadier/src/parse_results.rs index 3698ae82..aa7d79ea 100755 --- a/azalea-brigadier/src/parse_results.rs +++ b/azalea-brigadier/src/parse_results.rs @@ -4,13 +4,13 @@ use crate::{ }; use std::{collections::HashMap, fmt::Debug, rc::Rc}; -pub struct ParseResults<S> { - pub context: CommandContextBuilder<S>, +pub struct ParseResults<'a, S> { + pub context: CommandContextBuilder<'a, S>, pub reader: StringReader, pub exceptions: HashMap<Rc<CommandNode<S>>, CommandSyntaxException>, } -impl<S> Debug for ParseResults<S> { +impl<S> Debug for ParseResults<'_, S> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ParseResults") .field("context", &self.context) |
