Patch-Source: https://github.com/supabase/pg_graphql/pull/473 -- From bd6d3c4af27e7961e0c3d4632289d155336e399e Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Mon, 18 Dec 2023 19:20:43 +0100 Subject: [PATCH] replace regex with std alternative regex is a big dependency (adds over 1 MiB to the binary size) and it's unnecessary for such a simple check. --- Cargo.lock | 1 - Cargo.toml | 1 - src/graphql.rs | 10 +++------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcd2ab8d..16ef67c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1105,7 +1105,6 @@ dependencies = [ "pgrx", "pgrx-tests", "rand", - "regex", "serde", "serde_json", "uuid", diff --git a/Cargo.toml b/Cargo.toml index 88d0995d..610767b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ itertools = "0.10.3" cached = "0.34.0" rand = "0.8" uuid = "1" -regex = "1" base64 = "0.13" lazy_static = "1" bimap = { version = "0.6.3", features = ["serde"] } diff --git a/src/graphql.rs b/src/graphql.rs index 602153b3..f2a4e394 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -2,19 +2,15 @@ use crate::sql_types::*; use cached::proc_macro::cached; use cached::SizedCache; use itertools::Itertools; -use lazy_static::lazy_static; -use regex::Regex; use serde::Serialize; use std::collections::{HashMap, HashSet}; use std::ops::Deref; use std::sync::Arc; -lazy_static! { - static ref GRAPHQL_NAME_RE: Regex = Regex::new("^[_A-Za-z][_0-9A-Za-z]*$").unwrap(); -} - fn is_valid_graphql_name(name: &str) -> bool { - GRAPHQL_NAME_RE.is_match(name) + !name.is_empty() + && name.starts_with(|c: char| c == '_' || c.is_ascii_alphabetic()) + && name.chars().all(|c| c == '_' || c.is_ascii_alphanumeric()) } fn to_base_type_name(name: &str, name_override: &Option, inflect_names: bool) -> String {