buffer.compare - #234
Conversation
|
I think it'd be nice if we can also specify the offsets and length of the parts we want to compare |
|
I think the "Ranged comparison support" alternative is a much more powerful option, and with the suggested parameter list would be able to gracefully fall back anyway. I suspect |
Yeah, though imo |
Considering the existence of |
|
Alright that makes sense, I will update the rfc tomorrow |
|
Sort of unrelated, but can we get bitwise ops for buffers too (maybe implemented with SIMD)? A lot of the use cases I have for comparing buffers also benefit from bitwise ops. Just as a quick example, bitflags with more than 32 bits, currently you have to do a Luau loop and do it in chunks of u32 |
That would need to be a separate RFC entirely. |
That would be a game changing feature, Im interested to see your rfc on it if you decide to make one |
|
Alright updated it a bit |
i don't think the api needs to be designed around |
Rendered
This PR proposes adding
buffer.compare(b1, offset1, b2, offset2?, count?)to the standard buffer library. It performs an in-place, three-way lexicographic comparison over the underlying memory of two buffers, mimicking Cmemcmp. It returns0if the buffers are equal, a negative integer ifb1is less thanb2, and a positive integer ifb1is greater.