From 7af0fb10663009ab2a312c93198f5d83c7c5ff30 Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 4 Mar 2021 12:29:26 +0100 Subject: refactor(users/sterni/nix/string): don't calculate length for drop Since nix ends the substring at the end of the string anyways we can just statically use the largest nix integer as the length of the string. According to my testing this it ever so slightly faster as well. Change-Id: I64566e91c7b223f03dcebe3bc5710696dc4261bc Reviewed-on: https://cl.tvl.fyi/c/depot/+/2587 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/nix/string/default.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/users/sterni/nix/string/default.nix b/users/sterni/nix/string/default.nix index e2b27571c7..3fe7c04618 100644 --- a/users/sterni/nix/string/default.nix +++ b/users/sterni/nix/string/default.nix @@ -7,15 +7,16 @@ let ord ; - inherit (depot.users.sterni.nix.flow) - cond + inherit (depot.users.sterni.nix) + int + flow ; take = n: s: builtins.substring 0 n s; drop = n: s: - builtins.substring n (builtins.stringLength s - n) s; + builtins.substring n int.maxBound s; charAt = i: s: let @@ -26,7 +27,7 @@ let let len = builtins.stringLength s; go = i: - cond [ + flow.cond [ [ (i >= len) null ] [ (charAt i s == char) i ] [ true (go (i + 1)) ] -- cgit 1.4.1