From 6a44a3698df026e041aac289bc6c917515772398 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 13 Oct 2026 18:04:57 -0400 Subject: [PATCH] Remove underscores from floats in one pass --- src/prism.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/prism.c b/src/prism.c index 262c238fcb..1c8603b8ba 100644 --- a/src/prism.c +++ b/src/prism.c @@ -4145,12 +4145,16 @@ pm_double_parse(pm_parser_t *parser, const pm_token_t *token) { } } - // Next, handle underscores by removing them from the buffer. - for (size_t index = 0; index < length; index++) { - if (buffer[index] == '_') { - memmove((void *) (buffer + index), (void *) (buffer + index + 1), length - index); - length--; + /* + * Next, handle underscores by removing them from the buffer in a single + * pass to avoid quadratic-time copies. + */ + { + size_t write = 0; + for (size_t read = 0; read < length; read++) { + if (buffer[read] != '_') buffer[write++] = buffer[read]; } + length = write; } // Null-terminate the buffer so that strtod cannot read off the end.