Get the latest tech news
Giving C++ std:regex a C makeover
ullprogram.com/blog/2024/09/04/ Suppose you’re working in C using one of the major toolchains — that is, it’s mainly a C++ implementation — and you need regular expressions. You could integrate a library, but there’s a regex implementation in the C++ standard library included with your compiler, just within reach.
If matching lots of source strings, scope the arena to the loop and then the results, and any regex working memory, are automatically freed in O(1) at the end of each iteration: I can’t tell std::regex about the arena — it calls operator new the usual way, without extra arguments — so I have to smuggle it in through a thread-local variable: Interesting side note: In a rough benchmark these replacements made MSVC std::regex matching four times faster!
Or read this on Hacker News