Git fork

Merge branch 'jc/cat-file-batch-default-format-optim'

Optimize away strbuf_expand() call with a hardcoded formatting logic
specific for the default format in the --batch and --batch-check
options of "git cat-file".

* jc/cat-file-batch-default-format-optim:
cat-file: skip expanding default format

+35 -6
+23 -6
builtin/cat-file.c
··· 360 360 } 361 361 } 362 362 363 + static void print_default_format(struct strbuf *scratch, struct expand_data *data) 364 + { 365 + strbuf_addf(scratch, "%s %s %"PRIuMAX"\n", oid_to_hex(&data->oid), 366 + type_name(data->type), 367 + (uintmax_t)data->size); 368 + } 369 + 363 370 /* 364 371 * If "pack" is non-NULL, then "offset" is the byte offset within the pack from 365 372 * which the object may be accessed (though note that we may also rely on ··· 391 398 } 392 399 393 400 strbuf_reset(scratch); 394 - strbuf_expand(scratch, opt->format, expand_format, data); 395 - strbuf_addch(scratch, '\n'); 401 + 402 + if (!opt->format) { 403 + print_default_format(scratch, data); 404 + } else { 405 + strbuf_expand(scratch, opt->format, expand_format, data); 406 + strbuf_addch(scratch, '\n'); 407 + } 408 + 396 409 batch_write(opt, scratch->buf, scratch->len); 397 410 398 411 if (opt->batch_mode == BATCH_MODE_CONTENTS) { ··· 646 659 strbuf_release(&input); 647 660 } 648 661 662 + #define DEFAULT_FORMAT "%(objectname) %(objecttype) %(objectsize)" 663 + 649 664 static int batch_objects(struct batch_options *opt) 650 665 { 651 666 struct strbuf input = STRBUF_INIT; ··· 654 669 int save_warning; 655 670 int retval = 0; 656 671 657 - if (!opt->format) 658 - opt->format = "%(objectname) %(objecttype) %(objectsize)"; 659 - 660 672 /* 661 673 * Expand once with our special mark_query flag, which will prime the 662 674 * object_info to be handed to oid_object_info_extended for each ··· 664 676 */ 665 677 memset(&data, 0, sizeof(data)); 666 678 data.mark_query = 1; 667 - strbuf_expand(&output, opt->format, expand_format, &data); 679 + strbuf_expand(&output, 680 + opt->format ? opt->format : DEFAULT_FORMAT, 681 + expand_format, 682 + &data); 668 683 data.mark_query = 0; 669 684 strbuf_release(&output); 670 685 if (opt->transform_mode) 671 686 data.split_on_whitespace = 1; 672 687 688 + if (opt->format && !strcmp(opt->format, DEFAULT_FORMAT)) 689 + opt->format = NULL; 673 690 /* 674 691 * If we are printing out the object, then always fill in the type, 675 692 * since we will want to decide whether or not to stream.
+12
t/perf/p1006-cat-file.sh
··· 1 + #!/bin/sh 2 + 3 + test_description='Tests listing object info performance' 4 + . ./perf-lib.sh 5 + 6 + test_perf_large_repo 7 + 8 + test_perf 'cat-file --batch-check' ' 9 + git cat-file --batch-all-objects --batch-check 10 + ' 11 + 12 + test_done