mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Use static LazyLocks for all constant regexes (#22225)
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
Release Notes: - N/A
This commit is contained in:
parent
837bbc851f
commit
b93cee8d27
6 changed files with 43 additions and 33 deletions
|
@ -22,6 +22,7 @@ use paths::contexts_dir;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rpc::AnyProtoClient;
|
use rpc::AnyProtoClient;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Reverse,
|
cmp::Reverse,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
|
@ -753,8 +754,8 @@ impl ContextStore {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern = r" - \d+.zed.json$";
|
static ASSISTANT_CONTEXT_REGEX: LazyLock<Regex> =
|
||||||
let re = Regex::new(pattern).unwrap();
|
LazyLock::new(|| Regex::new(r" - \d+.zed.json$").unwrap());
|
||||||
|
|
||||||
let metadata = fs.metadata(&path).await?;
|
let metadata = fs.metadata(&path).await?;
|
||||||
if let Some((file_name, metadata)) = path
|
if let Some((file_name, metadata)) = path
|
||||||
|
@ -763,11 +764,15 @@ impl ContextStore {
|
||||||
.zip(metadata)
|
.zip(metadata)
|
||||||
{
|
{
|
||||||
// This is used to filter out contexts saved by the new assistant.
|
// This is used to filter out contexts saved by the new assistant.
|
||||||
if !re.is_match(file_name) {
|
if !ASSISTANT_CONTEXT_REGEX.is_match(file_name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(title) = re.replace(file_name, "").lines().next() {
|
if let Some(title) = ASSISTANT_CONTEXT_REGEX
|
||||||
|
.replace(file_name, "")
|
||||||
|
.lines()
|
||||||
|
.next()
|
||||||
|
{
|
||||||
contexts.push(SavedContextMetadata {
|
contexts.push(SavedContextMetadata {
|
||||||
title: title.to_string(),
|
title: title.to_string(),
|
||||||
path,
|
path,
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::{ops::RangeInclusive, sync::Arc, time::Duration};
|
use std::{
|
||||||
|
ops::RangeInclusive,
|
||||||
|
sync::{Arc, LazyLock},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail};
|
use anyhow::{anyhow, bail};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
@ -34,7 +38,8 @@ const DEV_MODE: bool = true;
|
||||||
const DEV_MODE: bool = false;
|
const DEV_MODE: bool = false;
|
||||||
|
|
||||||
const DATABASE_KEY_NAME: &str = "email_address";
|
const DATABASE_KEY_NAME: &str = "email_address";
|
||||||
const EMAIL_REGEX: &str = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b";
|
static EMAIL_REGEX: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b").unwrap());
|
||||||
const FEEDBACK_CHAR_LIMIT: RangeInclusive<i32> = 10..=5000;
|
const FEEDBACK_CHAR_LIMIT: RangeInclusive<i32> = 10..=5000;
|
||||||
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
||||||
"Feedback failed to submit, see error log for details.";
|
"Feedback failed to submit, see error log for details.";
|
||||||
|
@ -320,7 +325,7 @@ impl FeedbackModal {
|
||||||
let mut invalid_state_flags = InvalidStateFlags::empty();
|
let mut invalid_state_flags = InvalidStateFlags::empty();
|
||||||
|
|
||||||
let valid_email_address = match self.email_address_editor.read(cx).text_option(cx) {
|
let valid_email_address = match self.email_address_editor.read(cx).text_option(cx) {
|
||||||
Some(email_address) => Regex::new(EMAIL_REGEX).unwrap().is_match(&email_address),
|
Some(email_address) => EMAIL_REGEX.is_match(&email_address),
|
||||||
None => true,
|
None => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::{Arc, OnceLock};
|
use std::sync::{Arc, LazyLock};
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
@ -15,9 +15,9 @@ use git::{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn pull_request_number_regex() -> &'static Regex {
|
fn pull_request_number_regex() -> &'static Regex {
|
||||||
static PULL_REQUEST_NUMBER_REGEX: OnceLock<Regex> = OnceLock::new();
|
static PULL_REQUEST_NUMBER_REGEX: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"\(#(\d+)\)$").unwrap());
|
||||||
PULL_REQUEST_NUMBER_REGEX.get_or_init(|| Regex::new(r"\(#(\d+)\)$").unwrap())
|
&PULL_REQUEST_NUMBER_REGEX
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::OnceLock;
|
use std::{cell::RefCell, sync::LazyLock};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use markup5ever_rcdom::{Handle, NodeData};
|
use markup5ever_rcdom::{Handle, NodeData};
|
||||||
|
@ -10,13 +9,14 @@ use regex::Regex;
|
||||||
use crate::html_element::HtmlElement;
|
use crate::html_element::HtmlElement;
|
||||||
|
|
||||||
fn empty_line_regex() -> &'static Regex {
|
fn empty_line_regex() -> &'static Regex {
|
||||||
static REGEX: OnceLock<Regex> = OnceLock::new();
|
static REGEX: LazyLock<Regex> =
|
||||||
REGEX.get_or_init(|| Regex::new(r"^\s*$").unwrap())
|
LazyLock::new(|| Regex::new(r"^\s*$").expect("Failed to create empty_line_regex"));
|
||||||
|
®EX
|
||||||
}
|
}
|
||||||
|
|
||||||
fn more_than_three_newlines_regex() -> &'static Regex {
|
fn more_than_three_newlines_regex() -> &'static Regex {
|
||||||
static REGEX: OnceLock<Regex> = OnceLock::new();
|
static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\n{3,}").unwrap());
|
||||||
REGEX.get_or_init(|| Regex::new(r"\n{3,}").unwrap())
|
®EX
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum StartTagOutcome {
|
pub enum StartTagOutcome {
|
||||||
|
|
|
@ -10,13 +10,11 @@ use std::{
|
||||||
io::{BufRead, BufReader, Read},
|
io::{BufRead, BufReader, Read},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{Arc, LazyLock, OnceLock},
|
sync::{Arc, LazyLock},
|
||||||
};
|
};
|
||||||
use text::Anchor;
|
use text::Anchor;
|
||||||
use util::paths::PathMatcher;
|
use util::paths::PathMatcher;
|
||||||
|
|
||||||
static TEXT_REPLACEMENT_SPECIAL_CHARACTERS_REGEX: OnceLock<Regex> = OnceLock::new();
|
|
||||||
|
|
||||||
pub enum SearchResult {
|
pub enum SearchResult {
|
||||||
Buffer {
|
Buffer {
|
||||||
buffer: Model<Buffer>,
|
buffer: Model<Buffer>,
|
||||||
|
@ -265,16 +263,17 @@ impl SearchQuery {
|
||||||
regex, replacement, ..
|
regex, replacement, ..
|
||||||
} => {
|
} => {
|
||||||
if let Some(replacement) = replacement {
|
if let Some(replacement) = replacement {
|
||||||
let replacement = TEXT_REPLACEMENT_SPECIAL_CHARACTERS_REGEX
|
static TEXT_REPLACEMENT_SPECIAL_CHARACTERS_REGEX: LazyLock<Regex> =
|
||||||
.get_or_init(|| Regex::new(r"\\\\|\\n|\\t").unwrap())
|
LazyLock::new(|| Regex::new(r"\\\\|\\n|\\t").unwrap());
|
||||||
.replace_all(replacement, |c: &Captures| {
|
let replacement = TEXT_REPLACEMENT_SPECIAL_CHARACTERS_REGEX.replace_all(
|
||||||
match c.get(0).unwrap().as_str() {
|
replacement,
|
||||||
|
|c: &Captures| match c.get(0).unwrap().as_str() {
|
||||||
r"\\" => "\\",
|
r"\\" => "\\",
|
||||||
r"\n" => "\n",
|
r"\n" => "\n",
|
||||||
r"\t" => "\t",
|
r"\t" => "\t",
|
||||||
x => unreachable!("Unexpected escape sequence: {}", x),
|
x => unreachable!("Unexpected escape sequence: {}", x),
|
||||||
}
|
},
|
||||||
});
|
);
|
||||||
Some(regex.replace(text, replacement))
|
Some(regex.replace(text, replacement))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub mod test;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::sync::OnceLock;
|
use std::sync::{LazyLock, OnceLock};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cmp::{self, Ordering},
|
cmp::{self, Ordering},
|
||||||
|
@ -567,8 +567,9 @@ impl<'a> PartialOrd for NumericPrefixWithSuffix<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emoji_regex() -> &'static Regex {
|
fn emoji_regex() -> &'static Regex {
|
||||||
static EMOJI_REGEX: OnceLock<Regex> = OnceLock::new();
|
static EMOJI_REGEX: LazyLock<Regex> =
|
||||||
EMOJI_REGEX.get_or_init(|| Regex::new("(\\p{Emoji}|\u{200D})").unwrap())
|
LazyLock::new(|| Regex::new("(\\p{Emoji}|\u{200D})").unwrap());
|
||||||
|
&EMOJI_REGEX
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given string consists of emojis only.
|
/// Returns true if the given string consists of emojis only.
|
||||||
|
|
Loading…
Reference in a new issue