diff options
author | sterni <sternenseemann@systemli.org> | 2021-03-04T11·29+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-03-05T11·07+0000 |
commit | 7af0fb10663009ab2a312c93198f5d83c7c5ff30 (patch) | |
tree | bd6712b00aa2888174bf2ecdfb8bd13a41a503a9 /users/sterni/nix | |
parent | 8ff14cacb69dce491c81a629595087525b455a3f (diff) |
refactor(users/sterni/nix/string): don't calculate length for drop r/2267
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 <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni/nix')
-rw-r--r-- | users/sterni/nix/string/default.nix | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/users/sterni/nix/string/default.nix b/users/sterni/nix/string/default.nix index e2b27571c73f..3fe7c04618c3 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)) ] |