MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

optimize source position tracking by reusing last position data

+17 -5
+17 -5
src/silver/compiler.c
··· 216 216 if (end == off && off < (uint32_t)clen) end = off + 1; 217 217 if (end == off) return; 218 218 219 - uint32_t line = 1, col = 1; 220 - for (uint32_t i = 0; i < off; i++) { 221 - if (code[i] == '\n') { line++; col = 1; } 222 - else col++; 223 - } 224 219 if (c->srcpos_count > 0 && c->last_srcpos_off == off && c->last_srcpos_end == end) return; 220 + 221 + uint32_t line, col; 222 + if (c->srcpos_count > 0 && off >= c->last_srcpos_off) { 223 + line = c->srcpos[c->srcpos_count - 1].line; 224 + col = c->srcpos[c->srcpos_count - 1].col; 225 + for (uint32_t i = c->last_srcpos_off; i < off; i++) { 226 + if (code[i] == '\n') { line++; col = 1; } 227 + else col++; 228 + } 229 + } else { 230 + line = 1; col = 1; 231 + for (uint32_t i = 0; i < off; i++) { 232 + if (code[i] == '\n') { line++; col = 1; } 233 + else col++; 234 + } 235 + } 236 + 225 237 if (c->srcpos_count >= c->srcpos_cap) { 226 238 c->srcpos_cap = c->srcpos_cap ? c->srcpos_cap * 2 : 32; 227 239 c->srcpos = realloc(c->srcpos, (size_t)c->srcpos_cap * sizeof(sv_srcpos_t));