From 7974c6b1a0b2d07c5a337c89a70a51e01f629778 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Aug 2018 01:59:36 +0300 Subject: Mincrooptimization --- src/yellow/builder.rs | 4 ++-- src/yellow/green.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/yellow/builder.rs b/src/yellow/builder.rs index 70869952c..878f3ba39 100644 --- a/src/yellow/builder.rs +++ b/src/yellow/builder.rs @@ -41,11 +41,11 @@ impl<'a> Sink<'a> for GreenBuilder<'a> { fn finish_internal(&mut self) { let (kind, first_child) = self.parents.pop().unwrap(); - let children = self.children + let children: Vec<_> = self.children .drain(first_child..) .collect(); self.children.push( - GreenNode::new_branch(kind, children) + GreenNode::new_branch(kind, children.into_boxed_slice()) ); } diff --git a/src/yellow/green.rs b/src/yellow/green.rs index 5b4ce313a..57579a8f2 100644 --- a/src/yellow/green.rs +++ b/src/yellow/green.rs @@ -16,7 +16,7 @@ impl GreenNode { GreenNode::Leaf(GreenLeaf::new(kind, text)) } - pub(crate) fn new_branch(kind: SyntaxKind, children: Vec) -> GreenNode { + pub(crate) fn new_branch(kind: SyntaxKind, children: Box<[GreenNode]>) -> GreenNode { GreenNode::Branch(Arc::new(GreenBranch::new(kind, children))) } @@ -64,11 +64,11 @@ fn assert_send_sync() { pub(crate) struct GreenBranch { text_len: TextUnit, kind: SyntaxKind, - children: Vec, + children: Box<[GreenNode]>, } impl GreenBranch { - fn new(kind: SyntaxKind, children: Vec) -> GreenBranch { + fn new(kind: SyntaxKind, children: Box<[GreenNode]>) -> GreenBranch { let text_len = children.iter().map(|x| x.text_len()).sum::(); GreenBranch { text_len, @@ -86,7 +86,7 @@ impl GreenBranch { } pub fn children(&self) -> &[GreenNode] { - self.children.as_slice() + &*self.children } } -- cgit v1.2.3