Skip to content

Commit 9fd74cf

Browse files
committed
Use temporary variables to reduce memory stores
1 parent cbc421e commit 9fd74cf

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

ext/dom/html_document.c

+21-13
Original file line numberDiff line numberDiff line change
@@ -245,35 +245,43 @@ static void dom_find_line_and_column_using_cache(
245245
offset = application_data->current_input_length;
246246
}
247247

248+
size_t last_column = cache->last_column;
249+
size_t last_line = cache->last_line;
250+
size_t last_offset = cache->last_offset;
251+
248252
/* Either unicode or UTF-8 data */
249253
if (application_data->current_input_codepoints != NULL) {
250-
while (cache->last_offset < offset) {
251-
if (application_data->current_input_codepoints[cache->last_offset] == 0x000A /* Unicode codepoint for line feed */) {
252-
cache->last_line++;
253-
cache->last_column = 1;
254+
while (last_offset < offset) {
255+
if (application_data->current_input_codepoints[last_offset] == 0x000A /* Unicode codepoint for line feed */) {
256+
last_line++;
257+
last_column = 1;
254258
} else {
255-
cache->last_column++;
259+
last_column++;
256260
}
257-
cache->last_offset++;
261+
last_offset++;
258262
}
259263
} else {
260-
while (cache->last_offset < offset) {
261-
const lxb_char_t current = application_data->current_input_characters[cache->last_offset];
264+
while (last_offset < offset) {
265+
const lxb_char_t current = application_data->current_input_characters[last_offset];
262266
if (current == '\n') {
263-
cache->last_line++;
264-
cache->last_column = 1;
265-
cache->last_offset++;
267+
last_line++;
268+
last_column = 1;
269+
last_offset++;
266270
} else {
267271
/* See Lexbor tokenizer patch
268272
* Note for future self: branchlessly computing the length and jumping by the length would be nice,
269273
* however it takes so many instructions to do so that it is slower than this naive method. */
270274
if ((current & 0b11000000) != 0b10000000) {
271-
cache->last_column++;
275+
last_column++;
272276
}
273-
cache->last_offset++;
277+
last_offset++;
274278
}
275279
}
276280
}
281+
282+
cache->last_column = last_column;
283+
cache->last_line = last_line;
284+
cache->last_offset = last_offset;
277285
}
278286

279287
static void dom_lexbor_libxml2_bridge_tokenizer_error_reporter(

0 commit comments

Comments
 (0)