]> git.lizzy.rs Git - rust.git/commit
Reduce number of syscalls in `rand`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Sun, 26 Aug 2018 19:13:44 +0000 (21:13 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Sun, 26 Aug 2018 19:22:54 +0000 (21:22 +0200)
commit09a615c09761d5066b19d4b58a6a1d0e515ede45
treef8153ed4abd6ee15c1f314d38d0460572ca69619
parentcaed80ba4ba8d9f4d3fa8aa9af6c4092d779cd9d
Reduce number of syscalls in `rand`

In case that it is statically known that the OS doesn't support
`getrandom` (non-Linux) or becomes clear at runtime that `getrandom`
isn't available (`ENOSYS`), the opened fd ("/dev/urandom") isn't closed
after the function, so that future calls can reuse it. This saves
repeated `open`/`close` system calls at the cost of one permanently open
fd.

Additionally, this skips the initial zero-length `getrandom` call and
directly hands the user buffer to the operating system, saving one
`getrandom` syscall.
src/libstd/sys/unix/rand.rs