From 440af9fd647f81446be8bb14160059ab8fce9ed3 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 24 Apr 2023 09:41:33 -0500 Subject: [PATCH] Remove extra allocation in drop. --- src/boot/boot.janet | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c22fd764..cc280ae9 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1146,10 +1146,9 @@ (def use-str (bytes? ind)) (def f (if use-str string/slice tuple/slice)) (def len (length ind)) - (def [start end] - (if (>= n 0) - [(min n len) len] - [0 (max 0 (+ len n))])) + (def negn (>= n 0)) + (def start (if negn (min n len) 0)) + (def end (if negn len (max 0 (+ len n)))) (f ind start end)) (defn drop-until