Changes HashMap to use aHash instead, giving a performance boost. (#9391)

# Description

see https://github.com/nushell/nushell/issues/9390
using `ahash` instead of the default hasher. this will not affect
compile time as we where already building `ahash`.


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
Filip Andersson
2023-06-10 18:41:58 +02:00
committed by GitHub
parent e605d8007c
commit 1433f4a520
69 changed files with 124 additions and 93 deletions

View File

@ -159,8 +159,8 @@ impl PartialEq for HashableValue {
#[cfg(test)]
mod test {
use super::*;
use ahash::{HashMap, HashMapExt, HashSet, HashSetExt};
use nu_protocol::ast::{CellPath, PathMember};
use std::collections::{HashMap, HashSet};
#[test]
fn from_value() {

View File

@ -1,4 +1,5 @@
use super::hashable_value::HashableValue;
use ahash::{HashMap, HashMapExt};
use itertools::Itertools;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
@ -7,7 +8,6 @@ use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Type, Value,
};
use std::collections::HashMap;
use std::iter;
#[derive(Clone)]

View File

@ -1,11 +1,11 @@
use std::collections::HashMap;
use ahash::HashMap;
/// Return map of <deprecated_command_name, new_command_name>
/// This covers simple deprecated commands nicely, but it's not great for deprecating
/// subcommands like `foo bar` where `foo` is still a valid command.
/// For those, it's currently easiest to have a "stub" command that just returns an error.
pub fn deprecated_commands() -> HashMap<String, String> {
HashMap::from([
[
("keep".to_string(), "take".to_string()),
("match".to_string(), "find".to_string()),
("nth".to_string(), "select".to_string()),
@ -25,5 +25,7 @@ pub fn deprecated_commands() -> HashMap<String, String> {
("benchmark".to_string(), "timeit".to_string()),
("str collect".to_string(), "str join".to_string()),
("old-alias".to_string(), "alias".to_string()),
])
]
.into_iter()
.collect()
}

View File

@ -1,4 +1,5 @@
use std::{collections::HashMap, path::PathBuf};
use ahash::HashMap;
use std::path::PathBuf;
use nu_protocol::{
engine::{EngineState, Stack},

View File

@ -1,4 +1,4 @@
use std::collections::HashMap;
use ahash::{HashMap, HashMapExt};
use nu_engine::{eval_block, CallExt};
use nu_protocol::{

View File

@ -14,6 +14,7 @@ mod test_examples {
SplitRow, Str, StrJoin, StrLength, StrReplace, Update, Url, Values, Wrap,
};
use crate::{Each, To};
use ahash::{HashSet, HashSetExt};
use nu_cmd_lang::example_support::{
check_all_signature_input_output_types_entries_have_examples,
check_example_evaluates_to_expected_output,
@ -24,7 +25,6 @@ mod test_examples {
engine::{Command, EngineState, StateWorkingSet},
Type,
};
use std::collections::HashSet;
pub fn test_examples(cmd: impl Command + 'static) {
let examples = cmd.examples();

View File

@ -1,4 +1,4 @@
use std::collections::HashMap;
use ahash::{HashMap, HashMapExt};
#[cfg(all(
feature = "trash-support",
not(target_os = "android"),

View File

@ -1,3 +1,4 @@
use ahash::{HashMap, HashMapExt, HashSet, HashSetExt};
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
@ -5,7 +6,6 @@ use nu_protocol::{
Config, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::cmp::max;
use std::collections::{HashMap, HashSet};
#[derive(Clone)]
pub struct Join;

View File

@ -1,3 +1,4 @@
use ahash::{HashSet, HashSetExt};
use nu_engine::CallExt;
use nu_protocol::ast::{Call, CellPath, PathMember};
use nu_protocol::engine::{Command, EngineState, Stack};
@ -5,7 +6,6 @@ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
PipelineIterator, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::collections::HashSet;
#[derive(Clone)]
pub struct Select;

View File

@ -1,4 +1,5 @@
use crate::formats::value_to_string;
use ahash::{HashMap, HashMapExt};
use itertools::Itertools;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
@ -7,7 +8,6 @@ use nu_protocol::{
Span, Type, Value,
};
use std::collections::hash_map::IntoIter;
use std::collections::HashMap;
#[derive(Clone)]
pub struct Uniq;

View File

@ -1,3 +1,4 @@
use ahash::HashSet;
use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::{Block, Call};
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
@ -5,7 +6,6 @@ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
PipelineIterator, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::collections::HashSet;
use std::iter::FromIterator;
#[derive(Clone)]

View File

@ -1,4 +1,5 @@
use crate::formats::to::delimited::merge_descriptors;
use ahash::{HashMap, HashMapExt};
use fancy_regex::Regex;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
@ -9,7 +10,6 @@ use nu_protocol::{
};
use rust_embed::RustEmbed;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Write;

View File

@ -1,4 +1,5 @@
use crate::math::utils::run_with_function;
use ahash::{HashMap, HashMapExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Type, Value};
@ -142,7 +143,7 @@ pub fn mode(values: &[Value], _span: Span, head: &Span) -> Result<Value, ShellEr
})
.collect::<Result<Vec<HashableType>, ShellError>>()?;
let mut frequency_map = std::collections::HashMap::new();
let mut frequency_map = HashMap::new();
for v in hashable_values {
let counter = frequency_map.entry(v).or_insert(0);
*counter += 1;

View File

@ -9,7 +9,7 @@ use nu_protocol::{
};
use ureq::{Error, ErrorKind, Request, Response};
use std::collections::HashMap;
use ahash::{HashMap, HashMapExt};
use std::io::BufReader;
use std::path::PathBuf;
use std::str::FromStr;

View File

@ -1,7 +1,5 @@
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
use ahash::HashMap;
use std::path::{Path, PathBuf};
use nu_engine::CallExt;
use nu_protocol::ast::Call;

View File

@ -1,3 +1,4 @@
use ahash::{HashMap, HashMapExt};
use nu_ansi_term::*;
use nu_engine::CallExt;
use nu_protocol::engine::{EngineState, Stack};
@ -6,7 +7,6 @@ use nu_protocol::{
PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use once_cell::sync::Lazy;
use std::collections::HashMap;
#[derive(Clone)]
pub struct AnsiCommand;

View File

@ -1,4 +1,5 @@
use crate::hook::eval_hook;
use ahash::HashMap;
use nu_engine::env_to_strings;
use nu_engine::CallExt;
use nu_protocol::{
@ -11,7 +12,6 @@ use nu_protocol::{
use nu_system::ForegroundProcess;
use os_pipe::PipeReader;
use pathdiff::diff_paths;
use std::collections::HashMap;
use std::io::{BufRead, BufReader, Read, Write};
use std::path::{Path, PathBuf};
use std::process::{Command as CommandSys, Stdio};

View File

@ -1,3 +1,4 @@
use ahash::HashMap;
use nu_ansi_term::{Color, Style};
use nu_color_config::{get_color_map, StyleComputer};
use nu_engine::CallExt;
@ -11,7 +12,6 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::collections::HashMap;
/// A `less` like program to render a [Value] as a table.
#[derive(Clone)]

View File

@ -1,6 +1,6 @@
use ahash::HashMap;
use nu_protocol::{ShellError, Span};
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::path::Path;
// Attribution: Thanks exa. Most of this file is taken from around here
@ -86,7 +86,7 @@ impl Icons {
// }
static MAP_BY_NAME: Lazy<HashMap<&'static str, char>> = Lazy::new(|| {
HashMap::from([
[
(".Trash", '\u{f1f8}'), // 
(".atom", '\u{e764}'), // 
(".bashprofile", '\u{e615}'), // 
@ -124,7 +124,9 @@ static MAP_BY_NAME: Lazy<HashMap<&'static str, char>> = Lazy::new(|| {
("npmignore", '\u{e71e}'), // 
("rubydoc", '\u{e73b}'), // 
("yarn.lock", '\u{e718}'), // 
])
]
.into_iter()
.collect()
});
pub fn icon_for_file(file_path: &Path, span: Span) -> Result<char, ShellError> {