Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster byte_serialized_unchanged #1014

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dev-ardi
Copy link

@dev-ardi dev-ardi commented Dec 31, 2024

This uses a precomputed table.
This abuses the neat trick that ascii fits inside a u128.
https://godbolt.org/z/sh5MejEo5

To check that this is right you just need to call this in a loop and check the results:

    for i in 0..=255 {
        let res = byte_serialized_unchanged(i);
        println!("{}: {res}", i as char);
    }
: false
: false
: false
: false
: false
: false
: false
: false
: false
        : false

: false

: false

: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
 false
: false
: false
: false
: false
 : false
!: false
": false
#: false
$: false
%: false
&: false
': false
(: false
): false
*: true
+: false
,: false
-: true
.: true
/: false
0: true
1: true
2: true
3: true
4: true
5: true
6: true
7: true
8: true
9: true
:: false
;: false
<: false
=: false
>: false
?: false
@: false
A: true
B: true
C: true
D: true
E: true
F: true
G: true
H: true
I: true
J: true
K: true
L: true
M: true
N: true
O: true
P: true
Q: true
R: true
S: true
T: true
U: true
V: true
W: true
X: true
Y: true
Z: true
[: false
\: false
]: false
^: false
_: true
`: false
a: true
b: true
c: true
d: true
e: true
f: true
g: true
h: true
i: true
j: true
k: true
l: true
m: true
n: true
o: true
p: true
q: true
r: true
s: true
t: true
u: true
v: true
w: true
x: true
y: true
z: true
{: false
|: false
}: false
~: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
: false
 : false
¡: false
¢: false
£: false
¤: false
¥: false
¦: false
§: false
¨: false
©: false
ª: false
«: false
¬: false
­: false
®: false
¯: false
°: false
±: false
²: false
³: false
´: false
µ: false
¶: false
·: false
¸: false
¹: false
º: false
»: false
¼: false
½: false
¾: false
¿: false
À: false
Á: false
Â: false
Ã: false
Ä: false
Å: false
Æ: false
Ç: false
È: false
É: false
Ê: false
Ë: false
Ì: false
Í: false
Î: false
Ï: false
Ð: false
Ñ: false
Ò: false
Ó: false
Ô: false
Õ: false
Ö: false
×: false
Ø: false
Ù: false
Ú: false
Û: false
Ü: false
Ý: false
Þ: false
ß: false
à: false
á: false
â: false
ã: false
ä: false
å: false
æ: false
ç: false
è: false
é: false
ê: false
ë: false
ì: false
í: false
î: false
ï: false
ð: false
ñ: false
ò: false
ó: false
ô: false
õ: false
ö: false
÷: false
ø: false
ù: false
ú: false
û: false
ü: false
ý: false
þ: false
ÿ: false

@dev-ardi
Copy link
Author

dev-ardi commented Jan 1, 2025

Oh, this requires bumping the msrv

@hsivonen
Copy link
Collaborator

hsivonen commented Jan 3, 2025

It should be easy to write this as using a const function, which should make this work at least all the way back to Rust 1.57.

See

const fn glyphless_mask() -> u128 {
and
const GLYPHLESS_MASK: u128 = glyphless_mask();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants