# std: optimise utf8ByteSequenceLength · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/5843a6e3bc1a6353f76ebca57d6099337b90139a)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 5843a6e3bc1a6353f76ebca57d6099337b90139a

Requested commit: 5843a6e3bc1a6353f76ebca57d6099337b90139a

Commit: 5843a6e3bc1a6353f76ebca57d6099337b90139a

Tree: f1a0a0f0dce77adc395c5ae10bb1721732363641

Author: daurnimator

Committer: daurnimator

## Message

````
std: optimise utf8ByteSequenceLength

Also tested (but not as fast):
```zig
pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
    const len = @clz(u8, ~first_byte);
    if (len == 0) return 1;
    if (len < 4) return @intCast(u3, len);
    return error.Utf8InvalidStartByte;
}
```

````

## Parents

- [8b72eedc76f46b978843344f92605acb4ee4061a](https://git.cafe/gitcafe/zig/commit/8b72eedc76f46b978843344f92605acb4ee4061a?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/5843a6e3bc1a6353f76ebca57d6099337b90139a?format=markdown)
