hare

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

commit 5f863f64f982feb40a556be9f679cf52f8177425
parent 59e2c9f58b2a32c3e62d51da8a9656949bc735ae
Author: Sebastian <sebastian@sebsite.pw>
Date:   Thu, 21 Apr 2022 15:52:57 -0400

hare::module: more efficient identpath

Rather than allocating a new string for each path component, use
path::add to incrementally build a path, and only allocate once for the
returned string.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/module/context.ha | 10++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hare/module/context.ha b/hare/module/context.ha @@ -84,13 +84,11 @@ export fn identpath(name: ast::ident) str = { if (len(name) == 0) { return strings::dup("."); }; - let p = path::join(name[0]); - for (let i = 1z; i < len(name); i += 1) { - let q = path::join(p, name[i]); - free(p); - p = q; + let buf = path::init(); + for (let i = 0z; i < len(name); i += 1) { + path::add(&buf, name[i])!; }; - return p; + return path::allocate(&buf); }; @test fn identpath() void = {