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>
This commit is contained in:
parent
114bfa7d5c
commit
4f9b8a0702
@ -253,10 +253,7 @@ rec {
|
|||||||
=> false
|
=> false
|
||||||
*/
|
*/
|
||||||
hasInfix = infix: content:
|
hasInfix = infix: content:
|
||||||
let
|
builtins.match ".*${escapeRegex infix}.*" content != null;
|
||||||
drop = x: substring 1 (stringLength x) x;
|
|
||||||
in hasPrefix infix content
|
|
||||||
|| content != "" && hasInfix infix (drop content);
|
|
||||||
|
|
||||||
/* Convert a string to a list of characters (i.e. singleton strings).
|
/* 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,
|
This allows you to, e.g., map a function over each character. However,
|
||||||
|
@ -154,7 +154,7 @@ in
|
|||||||
hunspellDictionaries = with lib; filter isDerivation (unique (attrValues hunspellDicts));
|
hunspellDictionaries = with lib; filter isDerivation (unique (attrValues hunspellDicts));
|
||||||
# These dicts contain identically-named dict files, so we only keep the
|
# These dicts contain identically-named dict files, so we only keep the
|
||||||
# -large versions in case of clashes
|
# -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
|
otherDicts = with lib; filter
|
||||||
(d: !(hasAttr "dictFileName" d &&
|
(d: !(hasAttr "dictFileName" d &&
|
||||||
elem d.dictFileName (map (d: d.dictFileName) largeDicts)))
|
elem d.dictFileName (map (d: d.dictFileName) largeDicts)))
|
||||||
|
Loading…
Reference in New Issue
Block a user