Diff options
Diffstat (limited to 'source/ui-tree.c')
| -rw-r--r-- | source/ui-tree.c | 33 |
1 file changed, 7 insertions, 26 deletions
diff --git a/source/ui-tree.c b/source/ui-tree.c index 157aba3..aff4f0f 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -54,38 +54,19 @@ struct only_child { size_t count; }; -static void add_linenumber(struct strbuf *numbers, size_t lineno) -{ - strbuf_addf(numbers, "<a id='n%zu' href='#n%zu'>%zu</a>\n", lineno, lineno, lineno); -} - -/* - * The anchors are handed over in batches rather than a write per line, and - * never built whole, which would come to several times the blob's size. - */ static void print_linenumbers(const char *buf, size_t size) { - struct strbuf numbers = STRBUF_INIT; - size_t lineno = 0, idx = 0; + size_t lines = 0, idx; if (size) { - add_linenumber(&numbers, ++lineno); - + lines = 1; // The newline that ends the last line must not open a line of - // its own, so the final byte is left out of the scan. - while (idx < size - 1) { - if (buf[idx] == '\n') { - add_linenumber(&numbers, ++lineno); - if (numbers.len >= HTML_BATCH) { - html_raw(numbers.buf, numbers.len); - strbuf_reset(&numbers); - } - } - idx++; - } - html_raw(numbers.buf, numbers.len); + // its own, so the final byte is left out of the count. + for (idx = 0; idx < size - 1; idx++) + if (buf[idx] == '\n') + lines++; } - strbuf_release(&numbers); + cgit_print_line_anchors(1, lines); } static void print_text_buffer(const char *filename, char *buf, size_t size) |
