diff options
author | Russell Belfer <rb@github.com> | 2012-05-17 13:06:20 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-05-17 13:06:20 -0700 |
commit | b59c73d39a0bb3ddb6fd4e81f796018c2b3a0579 (patch) | |
tree | 27e61863405c09e510fe9d419a19366b20353cf9 /src/diff_output.c | |
parent | 706a9974a297ea1b38c6aab886b54598409725e8 (diff) | |
download | libgit2-b59c73d39a0bb3ddb6fd4e81f796018c2b3a0579.tar.gz |
Optimize away git_text_gather_stats in diff
GProf shows `git_text_gather_stats` as the most expensive call
in large diffs. The function calculates a lot of information
that is not actually used and does not do so in a optimal
order. This introduces a tuned `git_buf_is_binary` function
that executes the same algorithm in a fraction of the time.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r-- | src/diff_output.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/src/diff_output.c b/src/diff_output.c index 9c8e07972..4ad736e26 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -174,15 +174,12 @@ static int file_is_binary_by_content( git_map *new_data) { git_buf search; - git_text_stats stats; if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) { search.ptr = old_data->data; search.size = min(old_data->len, 4000); - git_text_gather_stats(&stats, &search); - - if (git_text_is_binary(&stats)) + if (git_buf_is_binary(&search)) delta->old_file.flags |= GIT_DIFF_FILE_BINARY; else delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY; @@ -192,9 +189,7 @@ static int file_is_binary_by_content( search.ptr = new_data->data; search.size = min(new_data->len, 4000); - git_text_gather_stats(&stats, &search); - - if (git_text_is_binary(&stats)) + if (git_buf_is_binary(&search)) delta->new_file.flags |= GIT_DIFF_FILE_BINARY; else delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY; |