commit fdde559890f98e92fc4ef9ba23f896e60d65c340
parent 6d7b8a15f118feda3929ee5fb7296167ee9a30b0
Author: Sebastian <sebastian@sebsite.pw>
Date: Sat, 9 Dec 2023 21:38:02 -0500
cmd/{hare,haredoc}: Don't allocate tags
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
7 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/cmd/hare/arch.ha b/cmd/hare/arch.ha
@@ -3,7 +3,6 @@
use hare::module;
use os;
-use strings;
// When building the bootstrap toolchain, these values will get overwritten to
// equal the values in config.mk
@@ -53,7 +52,7 @@ const arches: [_]arch = [
fn set_arch_tags(tags: *[]str, a: *arch) void = {
merge_tags(tags, "-aarch64-riscv64-x86_64")!;
- append(tags, strings::dup(a.name));
+ append(tags, a.name);
};
fn get_arch(name: str) (*arch | unknown_arch) = {
diff --git a/cmd/hare/build/types.ha b/cmd/hare/build/types.ha
@@ -8,7 +8,6 @@ use hare::module;
use io;
use os::exec;
use path;
-use strings;
export type error = !(exec::error | fs::error | io::error | module::error | path::error);
@@ -86,7 +85,7 @@ export type context = struct {
};
export fn ctx_finish(ctx: *context) void = {
- strings::freeall(ctx.ctx.tags);
+ free(ctx.ctx.tags);
for (let i = 0z; i < len(ctx.defines); i += 1) {
ast::ident_free(ctx.defines[i].ident);
ast::type_finish(ctx.defines[i]._type);
diff --git a/cmd/hare/deps.ha b/cmd/hare/deps.ha
@@ -11,7 +11,6 @@ use os;
use path;
use sort;
use sort::cmp;
-use strings;
type deps_fmt = enum {
DOT,
@@ -26,7 +25,7 @@ type link = struct {
fn deps(name: str, cmd: *getopt::command) (void | error) = {
let tags = default_tags();
- defer strings::freeall(tags);
+ defer free(tags);
let build_dir: str = "";
let goal = deps_fmt::TERM;
diff --git a/cmd/hare/util.ha b/cmd/hare/util.ha
@@ -11,7 +11,7 @@ use strings;
fn merge_tags(current: *[]str, new: str) (void | module::error) = {
let trimmed = strings::trimprefix(new, "^");
if (trimmed != new) {
- strings::freeall(*current);
+ free(*current);
*current = [];
};
let newtags = module::parse_tags(trimmed)?;
@@ -20,14 +20,13 @@ fn merge_tags(current: *[]str, new: str) (void | module::error) = {
for (let j = 0z; j < len(current); j += 1) {
if (newtags[i].name == current[j]) {
if (!newtags[i].include) {
- free(current[j]);
static delete(current[j]);
};
continue :new;
};
};
if (newtags[i].include) {
- append(current, strings::dup(newtags[i].name));
+ append(current, newtags[i].name);
};
};
};
@@ -43,10 +42,11 @@ fn harecache() str = {
};
};
-// result must be freed with strings::freeall
+// contents of slice shouldn't be freed
fn default_tags() []str = {
let arch = os::arch_name(os::architecture());
- let platform = ascii::strlower(os::sysname());
- let tags: []str = alloc([strings::dup(arch), platform]);
+ static let platform: [7]u8 = [0...];
+ let platform = ascii::strlower_buf(os::sysname(), platform[..0]);
+ let tags: []str = alloc([arch, platform]);
return tags;
};
diff --git a/cmd/haredoc/arch.ha b/cmd/haredoc/arch.ha
@@ -1,11 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-only
-// (c) Hare authors <https://harelang.org>
-
-use hare::module;
-use os;
-use strings;
-
-fn set_arch_tags(tags: *[]str, a: str) void = {
- merge_tags(tags, "-aarch64-riscv64-x86_64")!;
- append(tags, strings::dup(a));
-};
diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha
@@ -59,7 +59,7 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
let template = true;
let show_undocumented = false;
let tags: []str = default_tags();
- defer strings::freeall(tags);
+ defer free(tags);
for (let i = 0z; i < len(cmd.opts); i += 1) {
let opt = cmd.opts[i];
diff --git a/cmd/haredoc/util.ha b/cmd/haredoc/util.ha
@@ -13,7 +13,7 @@ def HAREPATH: str = ".";
fn merge_tags(current: *[]str, new: str) (void | module::error) = {
let trimmed = strings::ltrim(new, '^');
if (trimmed != new) {
- strings::freeall(*current);
+ free(*current);
*current = [];
};
let newtags = module::parse_tags(trimmed)?;
@@ -22,14 +22,13 @@ fn merge_tags(current: *[]str, new: str) (void | module::error) = {
for (let j = 0z; j < len(current); j += 1) {
if (newtags[i].name == current[j]) {
if (!newtags[i].include) {
- free(current[j]);
static delete(current[j]);
};
continue :new;
};
};
if (newtags[i].include) {
- append(current, strings::dup(newtags[i].name));
+ append(current, newtags[i].name);
};
};
};
@@ -45,10 +44,11 @@ fn harecache() str = {
};
};
-// result must be freed with strings::freeall
+// contents of slice shouldn't be freed
fn default_tags() []str = {
let arch = os::arch_name(os::architecture());
- let platform = ascii::strlower(os::sysname());
- let tags: []str = alloc([strings::dup(arch), platform]);
+ static let platform: [7]u8 = [0...];
+ let platform = ascii::strlower_buf(os::sysname(), platform[..0]);
+ let tags: []str = alloc([arch, platform]);
return tags;
};