Skip to content

Commit

Permalink
lib/strings: optimise hasInfix function (NixOS#168175)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: pennae <[email protected]>
  • Loading branch information
2 people authored and evanjs committed Jun 8, 2022
1 parent 1cfe9e4 commit 5f29d43
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/rstudio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 5f29d43

Please sign in to comment.