[php-src] master: Use temporary variables to reduce memory stores

From: Date: Sun, 17 Mar 2024 17:38:39 +0000
Subject: [php-src] master: Use temporary variables to reduce memory stores
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-127758@lists.php.net to get a copy of this message
Author: Niels Dossche (nielsdos) Date: 2024-03-17T18:21:59+01:00 Commit: https://github.com/php/php-src/commit/9fd74cfc9db24ef91d9723bb689c3bd3fa3c343f Raw diff: https://github.com/php/php-src/commit/9fd74cfc9db24ef91d9723bb689c3bd3fa3c343f.diff Use temporary variables to reduce memory stores Changed paths: M ext/dom/html_document.c Diff: diff --git a/ext/dom/html_document.c b/ext/dom/html_document.c index e60f4ea3a60c..46293cdf4c4e 100644 --- a/ext/dom/html_document.c +++ b/ext/dom/html_document.c @@ -245,35 +245,43 @@ static void dom_find_line_and_column_using_cache( offset = application_data->current_input_length; } + size_t last_column = cache->last_column; + size_t last_line = cache->last_line; + size_t last_offset = cache->last_offset; + /* Either unicode or UTF-8 data */ if (application_data->current_input_codepoints != NULL) { - while (cache->last_offset < offset) { - if (application_data->current_input_codepoints[cache->last_offset] == 0x000A /* Unicode codepoint for line feed */) { - cache->last_line++; - cache->last_column = 1; + while (last_offset < offset) { + if (application_data->current_input_codepoints[last_offset] == 0x000A /* Unicode codepoint for line feed */) { + last_line++; + last_column = 1; } else { - cache->last_column++; + last_column++; } - cache->last_offset++; + last_offset++; } } else { - while (cache->last_offset < offset) { - const lxb_char_t current = application_data->current_input_characters[cache->last_offset]; + while (last_offset < offset) { + const lxb_char_t current = application_data->current_input_characters[last_offset]; if (current == '\n') { - cache->last_line++; - cache->last_column = 1; - cache->last_offset++; + last_line++; + last_column = 1; + last_offset++; } else { /* See Lexbor tokenizer patch * Note for future self: branchlessly computing the length and jumping by the length would be nice, * however it takes so many instructions to do so that it is slower than this naive method. */ if ((current & 0b11000000) != 0b10000000) { - cache->last_column++; + last_column++; } - cache->last_offset++; + last_offset++; } } } + + cache->last_column = last_column; + cache->last_line = last_line; + cache->last_offset = last_offset; } static void dom_lexbor_libxml2_bridge_tokenizer_error_reporter(

« previous php.cvs (#127758) next »