on master help sign in
Cache the correct thing which setting which buffers are changing
ced46a4Neil Mitchell
cbits/hexml.c+18−14
@@ -385,22 +385,22 @@ void static inline parse_tag(document* d)
385{
385{
386 node_alloc(&d->nodes, 1);
386 node_alloc(&d->nodes, 1);
387 d->nodes.used_back++;
387 d->nodes.used_back++;
388− int me = d->nodes.size - d->nodes.used_back;
388+ node* me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back];
389
389
390− d->nodes.nodes[me].outer.start = doc_position(d);
390+ me->outer.start = doc_position(d);
391 char c = get(d);
391 char c = get(d);
392 assert(c == '<');
392 assert(c == '<');
393 if (peek(d) == '?') skip(d, 1);
393 if (peek(d) == '?') skip(d, 1);
394− d->nodes.nodes[me].name = parse_name(d);
394+ me->name = parse_name(d);
395− d->nodes.nodes[me].attrs = parse_attributes(d);
395+ me->attrs = parse_attributes(d);
396
396
397 c = get(d);
397 c = get(d);
398 if ((c == '/' || c == '?') && peek(d) == '>')
398 if ((c == '/' || c == '?') && peek(d) == '>')
399 {
399 {
400 skip(d, 1);
400 skip(d, 1);
401− d->nodes.nodes[me].nodes = start_length(0, 0);
401+ me->nodes = start_length(0, 0);
402− d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, doc_position(d)).length;
402+ me->outer.length = start_end(me->outer.start, doc_position(d)).length;
403− d->nodes.nodes[me].inner = start_length(doc_position(d), 0);
403+ me->inner = start_length(doc_position(d), 0);
404 return;
404 return;
405 }
405 }
406 else if (c != '>')
406 else if (c != '>')
@@ -408,22 +408,26 @@ void static inline parse_tag(document* d)
408 set_error(d, "Gunk at the end of the tag");
408 set_error(d, "Gunk at the end of the tag");
409 return;
409 return;
410 }
410 }
411− d->nodes.nodes[me].inner.start = doc_position(d);
411+ me->inner.start = doc_position(d);
412− d->nodes.nodes[me].nodes = parse_content(d);
412+ str content = parse_content(d);
413+
414+ // parse_content may have allocated more nodes, so recompute me
415+ me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back];
416+ me->nodes = content;
413− d->nodes.nodes[me].inner.length = start_end(d->nodes.nodes[me].inner.start, doc_position(d)).length;
417+ me->inner.length = start_end(me->inner.start, doc_position(d)).length;
414
418
415 if (d->error_message != NULL) return;
419 if (d->error_message != NULL) return;
416 if (peek(d) == '<' && peekAt(d, 1) == '/')
420 if (peek(d) == '<' && peekAt(d, 1) == '/')
417 {
421 {
418 skip(d, 2);
422 skip(d, 2);
419− if (d->end - d->cursor >= d->nodes.nodes[me].name.length &&
423+ if (d->end - d->cursor >= me->name.length &&
420− memcmp(d->cursor, &d->body[d->nodes.nodes[me].name.start], d->nodes.nodes[me].name.length) == 0)
424+ memcmp(d->cursor, &d->body[me->name.start], me->name.length) == 0)
421 {
425 {
422− skip(d, d->nodes.nodes[me].name.length);
426+ skip(d, me->name.length);
423 trim(d);
427 trim(d);
424 if (get(d) == '>')
428 if (get(d) == '>')
425 {
429 {
426− d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, doc_position(d)).length;
430+ me->outer.length = start_end(me->outer.start, doc_position(d)).length;
427 return;
431 return;
428 }
432 }
429 }
433 }