[libgit2-glib] Add delta/hunk caching for remaining diff functions



commit 593224ec9f196f109ad0ffc130dba683f6f0fccb
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Aug 17 15:56:45 2016 +0200

    Add delta/hunk caching for remaining diff functions

 libgit2-glib/ggit-diff.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/libgit2-glib/ggit-diff.c b/libgit2-glib/ggit-diff.c
index 0dd5f40..8cbcd4d 100644
--- a/libgit2-glib/ggit-diff.c
+++ b/libgit2-glib/ggit-diff.c
@@ -608,7 +608,6 @@ ggit_diff_foreach (GgitDiff              *diff,
 
        wrapper_data.user_data = user_data;
        wrapper_data.diff = diff;
-       wrapper_data.encoding = NULL;
 
        wrapper_data.cached_deltas = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_delta_unref);
        wrapper_data.cached_hunks = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_hunk_unref);
@@ -677,14 +676,19 @@ ggit_diff_print (GgitDiff              *diff,
 
        wrapper_data.user_data = user_data;
        wrapper_data.diff = diff;
-       wrapper_data.encoding = NULL;
 
        wrapper_data.line_cb = print_cb;
 
+       wrapper_data.cached_deltas = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_delta_unref);
+       wrapper_data.cached_hunks = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_hunk_unref);
+
        ret = git_diff_print (_ggit_native_get (diff), (git_diff_format_t)type,
                              ggit_diff_line_callback_wrapper,
                              &wrapper_data);
 
+       g_hash_table_destroy (wrapper_data.cached_deltas);
+       g_hash_table_destroy (wrapper_data.cached_hunks);
+
        if (ret != GIT_OK)
        {
                _ggit_error_set (error, ret);
@@ -824,8 +828,6 @@ ggit_diff_blobs (GgitBlob              *old_blob,
        gdiff_options = _ggit_diff_options_get_diff_options (diff_options);
 
        wrapper_data.user_data = user_data;
-       wrapper_data.diff = NULL;
-       wrapper_data.encoding = NULL;
 
        if (file_cb != NULL)
        {
@@ -851,6 +853,9 @@ ggit_diff_blobs (GgitBlob              *old_blob,
                wrapper_data.line_cb = line_cb;
        }
 
+       wrapper_data.cached_deltas = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_delta_unref);
+       wrapper_data.cached_hunks = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_hunk_unref);
+
        ret = git_diff_blobs (old_blob ? _ggit_native_get (old_blob) : NULL,
                              old_as_path,
                              new_blob ? _ggit_native_get (new_blob) : NULL,
@@ -860,6 +865,9 @@ ggit_diff_blobs (GgitBlob              *old_blob,
                              real_hunk_cb, real_line_cb,
                              &wrapper_data);
 
+       g_hash_table_destroy (wrapper_data.cached_deltas);
+       g_hash_table_destroy (wrapper_data.cached_hunks);
+
        if (ret != GIT_OK)
        {
                _ggit_error_set (error, ret);
@@ -914,8 +922,6 @@ ggit_diff_blob_to_buffer (GgitBlob              *old_blob,
        gdiff_options = _ggit_diff_options_get_diff_options (diff_options);
 
        wrapper_data.user_data = user_data;
-       wrapper_data.diff = NULL;
-       wrapper_data.encoding = NULL;
 
        if (buffer_len == -1)
        {
@@ -946,6 +952,9 @@ ggit_diff_blob_to_buffer (GgitBlob              *old_blob,
                wrapper_data.line_cb = line_cb;
        }
 
+       wrapper_data.cached_deltas = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_delta_unref);
+       wrapper_data.cached_hunks = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify) ggit_diff_hunk_unref);
+
        ret = git_diff_blob_to_buffer (old_blob ? _ggit_native_get (old_blob) : NULL,
                                       old_as_path,
                                       (const gchar *) buffer,
@@ -956,6 +965,9 @@ ggit_diff_blob_to_buffer (GgitBlob              *old_blob,
                                       real_hunk_cb, real_line_cb,
                                       &wrapper_data);
 
+       g_hash_table_destroy (wrapper_data.cached_deltas);
+       g_hash_table_destroy (wrapper_data.cached_hunks);
+
        if (ret != GIT_OK)
        {
                _ggit_error_set (error, ret);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]