From c826ce6fc6cf6e269e44d21595026d28d6238f63 Mon Sep 17 00:00:00 2001 From: Nia Date: Fri, 19 Sep 2025 03:51:41 +0200 Subject: [PATCH] markdown: Use the faster hasher (#38469) Micro-optimisation in the markdown crate to use the faster hasher. Release Notes: - N/A --- Cargo.lock | 1 + crates/markdown/Cargo.toml | 1 + crates/markdown/src/markdown.rs | 7 +++--- crates/markdown/src/parser.rs | 32 +++++++++++++++---------- crates/zed/src/zed/component_preview.rs | 2 +- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5654d206701f5efd5d91cd33c9ab456701b1e667..3acfed9bd7cfa8bc2742bb4f006c38a4f65a1f0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10418,6 +10418,7 @@ version = "0.1.0" dependencies = [ "assets", "base64 0.22.1", + "collections", "env_logger 0.11.8", "fs", "futures 0.3.31", diff --git a/crates/markdown/Cargo.toml b/crates/markdown/Cargo.toml index 9dfb3fdcd6c38f65357d93e5701cb0b72a6814a7..650338ef4f05485535313e408db64f0b7fe1188d 100644 --- a/crates/markdown/Cargo.toml +++ b/crates/markdown/Cargo.toml @@ -20,6 +20,7 @@ test-support = [ [dependencies] base64.workspace = true +collections.workspace = true futures.workspace = true gpui.workspace = true language.workspace = true diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index c2f8025e32d70cdd9500afdf0a4fc02a334a8521..fdf0f2bbf20190d15b533d02b9f0122746439c89 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -9,8 +9,6 @@ use log::Level; pub use path_range::{LineCol, PathWithRange}; use std::borrow::Cow; -use std::collections::HashMap; -use std::collections::HashSet; use std::iter; use std::mem; use std::ops::Range; @@ -19,6 +17,7 @@ use std::rc::Rc; use std::sync::Arc; use std::time::Duration; +use collections::{HashMap, HashSet}; use gpui::{ AnyElement, App, BorderStyle, Bounds, ClipboardItem, CursorStyle, DispatchPhase, Edges, Entity, FocusHandle, Focusable, FontStyle, FontWeight, GlobalElementId, Hitbox, Hsla, Image, @@ -176,7 +175,7 @@ impl Markdown { options: Options { parse_links_only: false, }, - copied_code_blocks: HashSet::new(), + copied_code_blocks: HashSet::default(), }; this.parse(cx); this @@ -199,7 +198,7 @@ impl Markdown { options: Options { parse_links_only: true, }, - copied_code_blocks: HashSet::new(), + copied_code_blocks: HashSet::default(), }; this.parse(cx); this diff --git a/crates/markdown/src/parser.rs b/crates/markdown/src/parser.rs index d60d34b41e7efc99970f72b15a8ea9c4c79eb6f9..1b4d5b5755c0b825124f37f68466bae7c0838b1a 100644 --- a/crates/markdown/src/parser.rs +++ b/crates/markdown/src/parser.rs @@ -4,7 +4,9 @@ pub use pulldown_cmark::TagEnd as MarkdownTagEnd; use pulldown_cmark::{ Alignment, CowStr, HeadingLevel, LinkType, MetadataBlockKind, Options, Parser, }; -use std::{collections::HashSet, ops::Range, path::Path, sync::Arc}; +use std::{ops::Range, path::Path, sync::Arc}; + +use collections::HashSet; use crate::path_range::PathWithRange; @@ -26,8 +28,8 @@ pub fn parse_markdown( HashSet>, ) { let mut events = Vec::new(); - let mut language_names = HashSet::new(); - let mut language_paths = HashSet::new(); + let mut language_names = HashSet::default(); + let mut language_paths = HashSet::default(); let mut within_link = false; let mut within_metadata = false; let mut parser = Parser::new_ext(text, PARSE_OPTIONS) @@ -579,8 +581,8 @@ mod tests { (30..37, Text), (30..37, End(MarkdownTagEnd::Paragraph)) ], - HashSet::new(), - HashSet::new() + HashSet::default(), + HashSet::default() ) ) } @@ -613,8 +615,8 @@ mod tests { (46..51, Text), (0..51, End(MarkdownTagEnd::Paragraph)) ], - HashSet::new(), - HashSet::new() + HashSet::default(), + HashSet::default() ) ); } @@ -670,8 +672,8 @@ mod tests { (43..53, SubstitutedText("–––––".into())), (0..53, End(MarkdownTagEnd::Paragraph)) ], - HashSet::new(), - HashSet::new() + HashSet::default(), + HashSet::default() ) ) } @@ -695,8 +697,12 @@ mod tests { (8..34, Text), (0..37, End(MarkdownTagEnd::CodeBlock)), ], - HashSet::from(["rust".into()]), - HashSet::new() + { + let mut h = HashSet::default(); + h.insert("rust".into()); + h + }, + HashSet::default() ) ); assert_eq!( @@ -716,8 +722,8 @@ mod tests { (4..16, Text), (4..16, End(MarkdownTagEnd::CodeBlock)) ], - HashSet::new(), - HashSet::new() + HashSet::default(), + HashSet::default() ) ); } diff --git a/crates/zed/src/zed/component_preview.rs b/crates/zed/src/zed/component_preview.rs index 176b176d59b23ed7f605988cf682c9d52dfdb95b..7a287cf3d83f24e7f4d42221bda420053a975860 100644 --- a/crates/zed/src/zed/component_preview.rs +++ b/crates/zed/src/zed/component_preview.rs @@ -216,7 +216,7 @@ impl ComponentPreview { } fn scope_ordered_entries(&self) -> Vec { - use std::collections::HashMap; + use collections::HashMap; let mut scope_groups: HashMap< ComponentScope,