hare

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

commit 4ed4b43b8d24fcaa75d0cb47d8d0692923ece5bb
parent 90c71c79c94ecd8cab21e7483349b4b16f169fd3
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  1 Apr 2021 13:13:08 -0400

strconv: cleanup nul terminator bits

Also removes a redundant buffer zeroing

Diffstat:
Mstrconv/itos.ha | 5++---
Mstrconv/utos.ha | 4+---
2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/strconv/itos.ha b/strconv/itos.ha @@ -9,8 +9,7 @@ export fn i64tosb(i: i64, b: base) const str = { static assert(types::I64_MAX == 9223372036854775807); if (i >= 0) return u64tosb(i: u64, b); - static let buf: [66]u8 = [0...]; // 64 binary digits plus NUL and - - buf = [0...]; + static let buf: [65]u8 = [0...]; // 64 binary digits plus - let s = types::string { data = &buf, ... }; @@ -18,7 +17,7 @@ export fn i64tosb(i: i64, b: base) const str = { s.length = 1; let u = strings::toutf8(u64tosb((-i): u64, b)); - assert(len(u) + 1 < len(buf)); + assert(len(u) < len(buf)); bytes::copy(buf[1..len(u) + 1], u); s.length += len(u); diff --git a/strconv/utos.ha b/strconv/utos.ha @@ -6,8 +6,7 @@ use types; // duplicate the result. export fn u64tosb(u: u64, b: base) const str = { static assert(types::U64_MAX == 18446744073709551615); - static let buf: [65]u8 = [0...]; // 64 binary digits plus NUL - buf = [0...]; + static let buf: [64]u8 = [0...]; // 64 binary digits static const lut_upper = [ '0', '1', '2', '3', '4', '5', '6', '7', @@ -34,7 +33,6 @@ export fn u64tosb(u: u64, b: base) const str = { }; bytes::reverse(buf[..s.length]); - buf[s.length] = 0; return *(&s: *str); };