5 ms·
I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.
by rkunde 4y ago
I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.
- layer8 4y agoWhat are the use cases for that, though?
- pkaye 4y agoMaybe for processing the code for an obfuscated C contest?
- xxpor 4y agoThere's a ton if you think of it as a byte array, rather than just a string. For example, network proxies that may remove various protocol TLV options from a packet.
- layer8 4y agoIs that an example of “remove all occurrences of a specific byte value from an array”? Wouldn’t packet processing require some sort of structural parsing?
- xxpor 4y agoPackets are usually parsed by casting a uint8_t * to a struct. Frequently, the part that needs to be removed is always at the same offset in the non-error case.
- eklitzke 4y agoThis particular routine doesn't seem that useful, but sometimes these weird vector algorithms that don't seem useful on their own are composed together in interesting ways to solve a larger, more interesting problem. For example, there was a cppcon talk a few years ago where the presenter came up with a novel way of using AVX instructions to efficiently find the median of seven (yes, exactly seven) integers, by coming up with a novel representation of the problem that AVX instructions were well-suited for.^[1] That said, I don't know if this particular routine is something the author came up with while working on some other problem, or if it's just a neat idea that he came up with and wrote a short blog post about. [1] https://www.youtube.com/watch?v=qejTqnxQRcw https://www.youtube.com/watch?v=qejTqnxQRcw
- tuananh 4y agobetter word is compact?