From b012df90bbd796f8805d570688cb4a29f9ea8a15 Mon Sep 17 00:00:00 2001 From: John Lindal Date: Fri, 26 Apr 2024 11:27:01 -0700 Subject: [PATCH] optimize yy_get_next_buffer by switching to memmove based on https://lists.defectivebydesign.org/archive/html/help-flex/2013-01/msg00000.html --- src/c99-flex.skl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/c99-flex.skl b/src/c99-flex.skl index b18413ba7..b7b0d57fc 100644 --- a/src/c99-flex.skl +++ b/src/c99-flex.skl @@ -1079,9 +1079,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* First move last chars to start of buffer. */ number_to_move = (int) (yyscanner->yy_c_buf_p - yyscanner->yytext_ptr - 1); - for ( i = 0; i < number_to_move; ++i ) { - *(dest++) = *(source++); - } + if (number_to_move > 0) + memmove(dest, source, number_to_move * sizeof(*source)); + if ( yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_buffer_status == YY_BUFFER_EOF_PENDING ) { /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF