Skip to content

scrub() in C++, without regular expressions - #64

Merged
AlbanSagouis merged 9 commits into
devfrom
perf/cpp-scrub
Nov 24, 2026
Merged

AlbanSagouis merged 9 commits into
devfrom
perf/cpp-scrub

Conversation

@AlbanSagouis

@AlbanSagouis AlbanSagouis commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Moves the input cleaning scrub() from two gsub() calls to one regex-free C++ loop (src/scrub.cpp). scrub() in R becomes pz_scrub(enc2utf8(num_to_chr(x))). Its output was pinned beforehand by tests/testthat/test-scrub.R (1085 strings from the tests plus edge cases), and that file passes unchanged. Strings marked "bytes" now give an error, as invalid UTF-8 already did.

Speedup of parse_lat() measured on CI in this PR (old time / new time, same run): macOS 1.81x, Ubuntu 1.56x to 1.72x, Windows 1.31x. scrub() alone is 6.7 times faster on macOS.

@AlbanSagouis
AlbanSagouis marked this pull request as ready for review November 19, 2026 16:18
The scrub() half of bc796b8. check_encoding() in R/zzz.R stops on strings marked "bytes" and on latin1 strings with a byte that Windows-1252 leaves undefined. The C++ "bytes" check in src/scrub.cpp can no longer fire and is removed. The format path does not call check_encoding() yet.
…dling of latin1 junk bytes

On this branch the format path does not call check_encoding(), so the test pinned what R does with the byte 0x81: an error on macOS, NA with a warning on Windows. #65 replaces it with parzer's own error, the same on every platform.
@AlbanSagouis
AlbanSagouis merged commit f928b95 into dev Nov 24, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant