From 5f29d43ccea16fdfe4485b35afb3894599ce62b4 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Fri, 22 Apr 2022 17:43:25 +0100 Subject: [PATCH] lib/strings: optimise hasInfix function (#168175) * lib/strings: optimise hasInfix function * lib/strings: optimise hasInfix further using regex * rstudio: call hasInfix with a string * lib/strings: remove let from hasInfix Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> --- lib/strings.nix | 5 +---- pkgs/applications/editors/rstudio/default.nix | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index 820d1901f945b..11066890ec3d3 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -253,10 +253,7 @@ rec { => false */ hasInfix = infix: content: - let - drop = x: substring 1 (stringLength x) x; - in hasPrefix infix content - || content != "" && hasInfix infix (drop content); + builtins.match ".*${escapeRegex infix}.*" content != null; /* Convert a string to a list of characters (i.e. singleton strings). This allows you to, e.g., map a function over each character. However, diff --git a/pkgs/applications/editors/rstudio/default.nix b/pkgs/applications/editors/rstudio/default.nix index eada77eea8433..8d4aa112cdb66 100644 --- a/pkgs/applications/editors/rstudio/default.nix +++ b/pkgs/applications/editors/rstudio/default.nix @@ -154,7 +154,7 @@ in hunspellDictionaries = with lib; filter isDerivation (unique (attrValues hunspellDicts)); # These dicts contain identically-named dict files, so we only keep the # -large versions in case of clashes - largeDicts = with lib; filter (d: hasInfix "-large-wordlist" d) hunspellDictionaries; + largeDicts = with lib; filter (d: hasInfix "-large-wordlist" d.name) hunspellDictionaries; otherDicts = with lib; filter (d: !(hasAttr "dictFileName" d && elem d.dictFileName (map (d: d.dictFileName) largeDicts)))