hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit aeb2be7e9f8400d788483e76db517d42020fa8c0
parent 7b2866d036812a92ad614f5d9b98cac26dc1303c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 30 Jan 2021 15:16:16 -0500

os: use static argument array if possible

Diffstat:
Mos/+linux/environ.ha | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -6,9 +6,18 @@ use types; // member is usually the name of the program. export let args: []str = []; +// Statically allocate arg strings if there are few enough arguments, saves a +// syscall if we don't need it. +let args_static: [32]str = [""...]; + @init fn init() void = { - args = alloc([]str, [], rt::argc); - (&args: *types::slice).length = rt::argc; // HORRIBLE HACK + if (rt::argc < len(args_static)) { + args = args_static[..rt::argc]; + } else { + args = alloc([]str, [], rt::argc); + (&args: *types::slice).length = rt::argc; // HORRIBLE HACK + }; + for (let i = 0z; i < rt::argc; i += 1z) { args[i] = strings::from_c(rt::argv[i]); };