hare

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

commit 15205afb16a94e52561424676143fc3113985193
parent fb35c93aaeb8815bf8f821d372de741863ca3344
Author: iamthenoname <iamthenoname@perso.be>
Date:   Fri, 25 Aug 2023 17:49:03 +0800

unix::passwd: improve getuid and getgid performance

Diffstat:
Munix/passwd/group.ha | 8++++++--
Munix/passwd/passwd.ha | 14++++++++------
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/unix/passwd/group.ha b/unix/passwd/group.ha @@ -79,8 +79,10 @@ export fn getgroup(name: str) (grent | void) = { }; defer io::close(file)!; + let rbuf: [os::BUFSZ]u8 = [0...]; + let strm = bufio::init(file, rbuf, []); for (true) { - let ent = match (nextgr(file)) { + let ent = match (nextgr(&strm)) { case let e: grent => yield e; case io::EOF => @@ -110,8 +112,10 @@ export fn getgid(gid: uint) (grent | void) = { }; defer io::close(file)!; + let rbuf: [os::BUFSZ]u8 = [0...]; + let strm = bufio::init(file, rbuf, []); for (true) { - let ent = match (nextgr(file)) { + let ent = match (nextgr(&strm)) { case let e: grent => yield e; case io::EOF => diff --git a/unix/passwd/passwd.ha b/unix/passwd/passwd.ha @@ -29,8 +29,8 @@ export type pwent = struct { // Reads a Unix-like password entry from an [[io::handle]]. The caller must free // the return value using [[pwent_finish]]. -export fn nextpw(file: io::handle) (pwent | io::EOF | io::error | invalid) = { - let line = match (bufio::scanline(file)?) { +export fn nextpw(in: io::handle) (pwent | io::EOF | io::error | invalid) = { + let line = match (bufio::scanline(in)?) { case io::EOF => return io::EOF; case let ln: []u8 => @@ -98,8 +98,10 @@ export fn getuser(username: str) (pwent | void) = { }; defer io::close(file)!; + let rbuf: [os::BUFSZ]u8 = [0...]; + let strm = bufio::init(file, rbuf, []); for (true) { - let ent = match (nextpw(file)) { + let ent = match (nextpw(&strm)) { case let e: pwent => yield e; case io::EOF => @@ -114,8 +116,6 @@ export fn getuser(username: str) (pwent | void) = { pwent_finish(&ent); }; }; - - return; }; // Looks up a user by ID in a Unix-like password file. It expects a password @@ -132,8 +132,10 @@ export fn getuid(uid: uint) (pwent | void) = { }; defer io::close(file)!; + let rbuf: [os::BUFSZ]u8 = [0...]; + let strm = bufio::init(file, rbuf, []); for (true) { - let ent = match (nextpw(file)) { + let ent = match (nextpw(&strm)) { case let e: pwent => yield e; case io::EOF =>