diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-08-09 17:46:47 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-08-09 18:54:04 -0400 |
| commit | 0d29cc3375d4f20e122df23726cc526f96bf3305 (patch) | |
| tree | a2002a263414fbbcc5b114eb3a8a7406b1c92799 /core/bytes/bytes.odin | |
| parent | c8a62ee4ec9b7beec6dcff907ad2dfecdd547f22 (diff) | |
Use `for x in y` construct for `bytes` iteration
This cannot be applied to the `strings` version, as that would cause a
rune-by-rune iteration, not a byte-by-byte one.
Diffstat (limited to 'core/bytes/bytes.odin')
| -rw-r--r-- | core/bytes/bytes.odin | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin index 4edd089b9..e130502a1 100644 --- a/core/bytes/bytes.odin +++ b/core/bytes/bytes.odin @@ -298,8 +298,8 @@ split_after_iterator :: proc(s: ^[]byte, sep: []byte) -> ([]byte, bool) { index_byte :: proc(s: []byte, c: byte) -> int { _index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int { - for i := 0; i < len(s); i += 1 { - if s[i] == c { + for ch, i in s { + if ch == c { return i } } @@ -319,8 +319,8 @@ index_byte :: proc(s: []byte, c: byte) -> int { // Returns -1 if c is not present last_index_byte :: proc(s: []byte, c: byte) -> int { _last_index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int { - for i := len(s)-1; i >= 0; i -= 1 { - if s[i] == c { + #reverse for ch, i in s { + if ch == c { return i } } |