JL_DLLEXPORT uint64_t jl_ios_get_nbyte_int(ios_t *s, const size_t n) { assert(n <= 8); size_t space, ret; do { space = (size_t)(s->size - s->bpos); ret = ios_readprep(s, n); if (space == ret && ret < n) jl_eof_error(); } while(ret < n); uint64_t x = 0; uint8_t *buf = (uint8_t*)&s->buf[s->bpos]; if (n == 8) { // expecting loop unrolling optimization for (size_t i = 0; i < 8; i++) x |= (uint64_t)buf[i] << (i << 3); } else if (n >= 4) { // expecting loop unrolling optimization for (size_t i = 0; i < 4; i++) x |= (uint64_t)buf[i] << (i << 3); for (size_t i = 4; i < n; i++) x |= (uint64_t)buf[i] << (i << 3); } else { for (size_t i = 0; i < n; i++) x |= (uint64_t)buf[i] << (i << 3); } s->bpos += n; return x; }
JL_DLLEXPORT int jl_fs_read_byte(int handle) { uv_fs_t req; char c; uv_buf_t buf[1]; buf[0].base = &c; buf[0].len = 1; int ret = uv_fs_read(jl_io_loop, &req, handle, buf, 1, -1, NULL); uv_fs_req_cleanup(&req); switch (ret) { case -1: return ret; case 0: jl_eof_error(); case 1: return (int)c; default: assert(0 && "jl_fs_read_byte: Invalid return value from uv_fs_read"); return -1; } }