The previous C code was troublesome. - Didn't handle long lines - I couldn't convince myself that it was free of memory safety issues - Needed improving anyway, there are some formatting bugs. These are hard to fix in the current code. I mostly replicated the formatting bugs of the old C implementation in Rust, and possibly added a few new bugs as well. It's not a significant improvement right now, more testing and fixing will be needed. The performance of both implementations is comparable, with the Rust version being slightly faster in many cases (and slower in some others). I did spend more time trying to optimize this Rust version than I did with the old C code. I initially tried a naive-ish conversion of the C code to Rust, but that turned out to be much slower and I had to resort to using regexes and different data structures fix that.
28 lines
549 B
Text
28 lines
549 B
Text
#include "EXTERN.h"
|
|
#include "perl.h"
|
|
#include "XSUB.h"
|
|
|
|
struct StringWrap {
|
|
char *buf;
|
|
unsigned long long len, cap;
|
|
};
|
|
|
|
struct StringWrap grotty2html_wrap(const char *, unsigned long long);
|
|
void grotty2html_free(struct StringWrap);
|
|
|
|
|
|
MODULE = ManUtils PACKAGE = ManUtils
|
|
|
|
SV *
|
|
html(str)
|
|
SV *str
|
|
CODE:
|
|
STRLEN len;
|
|
char *inbuf = SvPV(str, len);
|
|
struct StringWrap buf = grotty2html_wrap(inbuf, len);
|
|
SV *dest = newSVpv(buf.buf, buf.len);
|
|
grotty2html_free(buf);
|
|
SvUTF8_on(dest);
|
|
RETVAL = dest;
|
|
OUTPUT:
|
|
RETVAL
|