hare

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

commit c9386573e9e3d247c938ae16a2da7aa7802be395
parent e2ed5908ea4b0e001e5f6176443995a7c14d0b28
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat,  9 Dec 2023 22:13:26 -0500

cmd/haredoc: replace split with rtokenize

So a slice doesn't need to be allocated

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

Diffstat:
Mcmd/haredoc/main.ha | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -353,18 +353,22 @@ fn has_decl(decl: ast::decl, name: str) bool = { if (len(d.ident) == 1 && d.ident[0] == name) { return true; }; - const sym = strings::split(d.symbol, "."); - defer free(sym); - return len(sym) > 0 && sym[len(sym) - 1] == name; + let tok = strings::rtokenize(d.symbol, "."); + match (strings::next_token(&tok)) { + case void => void; + case let s: str => + return s == name; + }; case let d: []ast::decl_global => for (let i = 0z; i < len(d); i += 1) { if (len(d[i].ident) == 1 && d[i].ident[0] == name) { return true; }; - const sym = strings::split(d[i].symbol, "."); - defer free(sym); - if (len(sym) > 0 && sym[len(sym) - 1] == name) { - return true; + let tok = strings::rtokenize(d[i].symbol, "."); + match (strings::next_token(&tok)) { + case void => void; + case let s: str => + return s == name; }; }; case let d: []ast::decl_type =>