←back to thread

103 points vortex_ape | 1 comments | | HN request time: 0.205s | source
1. purplesyringa ◴[] No.42744606[source]
Instead of

    let surrogate_mask = surrogate_bit << 2 | surrogate_bit << 1 | surrogate_bit;
    len &= !surrogate_mask;
consider

    len &= surrogate_bit.wrapping_sub(1);
This should still work better. Alternatively, invert the conditions and do

    len &= non_surrogate_bit.wrapping_neg();