diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-27 22:31:46 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-27 22:31:46 +0100 |
| commit | c4d19dfa925ffe44c04fcda90543a272b7165274 (patch) | |
| tree | c493697ab16154885febf04511f7f61e64b4bbbb /core/bytes/buffer.odin | |
| parent | 35e70f4be17f4123ec25108d664864f13b38087e (diff) | |
Use `uint` instead of `int` to improve code generation for bounds checking
Diffstat (limited to 'core/bytes/buffer.odin')
| -rw-r--r-- | core/bytes/buffer.odin | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index d9f195871..bba834f7e 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -240,14 +240,11 @@ buffer_read_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int) -> (n: int, err: io. buffer_read_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) { b.last_read = .Invalid - if offset < 0 || offset >= len(b.buf) { + if uint(offset) >= len(b.buf) { err = .Invalid_Offset return } - - if 0 <= offset && offset < len(b.buf) { - n = copy(p, b.buf[offset:]) - } + n = copy(p, b.buf[offset:]) if n > 0 { b.last_read = .Read } |