hare

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

commit 04da54aa69972d48e898bae3d4c48b38641bd44e
parent 57fbb5d81c32021f7df3badba39638c80890f598
Author: Autumn! <autumnull@posteo.net>
Date:   Sun,  7 May 2023 01:43:22 +0000

path: remove allocate()

Signed-off-by: Autumn! <autumnull@posteo.net>

Diffstat:
Mcmd/hare/plan.ha | 2+-
Mhare/module/context.ha | 2+-
Mpath/buffer.ha | 10++--------
3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -116,7 +116,7 @@ fn mkplan( context = ctx, target = target, workdir = os::tryenv("HARE_DEBUG_WORKDIR", temp::dir()), - script = path::allocate(&buf), + script = strings::dup(path::string(&buf)), environ = alloc([ (strings::dup("HARECACHE"), strings::dup(ctx.cache)), ]), diff --git a/hare/module/context.ha b/hare/module/context.ha @@ -97,7 +97,7 @@ export fn identpath(name: ast::ident) str = { for (let i = 0z; i < len(name); i += 1) { path::add(&buf, name[i])!; }; - return path::allocate(&buf); + return strings::dup(path::string(&buf)); }; @test fn identpath() void = { diff --git a/path/buffer.ha b/path/buffer.ha @@ -25,8 +25,8 @@ export fn set(buf: *buffer, items: str...) (str | errors::overflow) = { }; // Returns the current path stored in this buffer. -// The return value is borrowed from the buffer. Use [[allocate]] to extend -// the lifetime of the string. +// The return value is borrowed from the buffer. Use [[strings::dup]] to +// extend the lifetime of the string. export fn string(buf: *buffer) str = { const value = strings::fromutf8_unsafe(buf.buf[..buf.end]); if (value == "") { @@ -35,12 +35,6 @@ export fn string(buf: *buffer) str = { return value; }; -// Like [[string]] but the return value is copied to the heap and must be -// freed by the caller. -export fn allocate(buf: *buffer) str = { - return strings::dup(string(buf)); -}; - const dot: []u8 = ['.']; const dotdot: []u8 = ['.', '.']; const dotdotslash: []u8 = ['.', '.', PATHSEP];