Skip to content

Implement some minor performance optimizations #4283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion compiler/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ log = "0.4.16"
num-bigint = "0.4.3"
num-traits = "0.2.14"
phf = "0.10.1"
rustc-hash = "1.1.0"
thiserror = "1.0"
unic-emoji-char = "0.9.0"
unic-ucd-ident = "0.9.0"
unicode_names2 = "0.5.0"
thiserror = "1.0"

[dev-dependencies]
insta = "1.14.0"
6 changes: 3 additions & 3 deletions compiler/parser/src/function.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::ast;
use crate::error::{LexicalError, LexicalErrorType};
use ahash::RandomState;
use std::collections::HashSet;
use rustc_hash::FxHashSet;

pub struct ArgumentList {
pub args: Vec<ast::Expr>,
Expand Down Expand Up @@ -54,7 +53,8 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentList, Lexi
let mut args = vec![];
let mut keywords = vec![];

let mut keyword_names = HashSet::with_capacity_and_hasher(func_args.len(), RandomState::new());
let mut keyword_names =
FxHashSet::with_capacity_and_hasher(func_args.len(), Default::default());
for (name, value) in func_args {
match name {
Some((start, end, name)) => {
Expand Down
13 changes: 13 additions & 0 deletions compiler/parser/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ pub fn parse_strings(
let initial_end = values[0].2;
let initial_kind = (values[0].1 .1 == StringKind::U).then(|| "u".to_owned());

// Optimization: fast-track the common case of a single string.
if matches!(&*values, [(_, (_, StringKind::Normal | StringKind::U), _)]) {
let value = values.into_iter().last().unwrap().1 .0;
return Ok(Expr::new(
initial_start,
initial_end,
ExprKind::Constant {
value: Constant::Str(value),
kind: initial_kind,
},
));
}

// Determine whether the list of values contains any f-strings. (If not, we can return a
// single Constant at the end, rather than a JoinedStr.)
let mut has_fstring = false;
Expand Down