From 2771e2cd316961b3c1988a2e304bd5d324e451bb Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 4 Mar 2022 19:44:08 +0800 Subject: [PATCH] performance improved --- src/util/sum.scad | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/sum.scad b/src/util/sum.scad index 1bc28a97..4d66c5ec 100644 --- a/src/util/sum.scad +++ b/src/util/sum.scad @@ -9,5 +9,8 @@ **/ function sum(lt) = - let(leng = len(lt)) - [for(i = 0; i < leng; i = i + 1) 1] * lt; \ No newline at end of file + let( + end = len(lt) - 1, + cum_total = [for(i = 0, s = lt[0]; i < end; i = i + 1, s = s + lt[i]) s] + ) + cum_total[len(cum_total) - 1] + lt[end]; \ No newline at end of file