<commit_before>﻿using System.Collections.Generic;
using System.Threading.Tasks;
using LibGit2Sharp;

namespace GitNStats.Core
{
    public interface AsyncVisitor
    {
        Task<IEnumerable<(Commit Commit, TreeEntryChanges Diff)>> Walk(Commit commit);
    }

    public class DiffCollector : AsyncVisitor
    {
        private readonly Visitor _visitor;
        private readonly IDiffListener _listener;

        public DiffCollector(Visitor visitor, IDiffListener listener)
        {
            _visitor = visitor;
            _listener = listener;
        }

        public Task<IEnumerable<(Commit Commit, TreeEntryChanges Diff)>> Walk(Commit commit)
        {
            return Task.Run(() =>
            {
                _visitor.Visited += _listener.OnCommitVisited;
                try
                {
                    _visitor.Walk(commit);
                    return Task.FromResult(_listener.Diffs);
                }
                finally
                {
                    _visitor.Visited -= _listener.OnCommitVisited;
                }
            });
        }
    }
}<commit_msg>Remove useless Task.FromResult<commit_after>﻿using System.Collections.Generic;
using System.Threading.Tasks;
using LibGit2Sharp;

namespace GitNStats.Core
{
    public interface AsyncVisitor
    {
        Task<IEnumerable<(Commit Commit, TreeEntryChanges Diff)>> Walk(Commit commit);
    }

    public class DiffCollector : AsyncVisitor
    {
        private readonly Visitor _visitor;
        private readonly IDiffListener _listener;

        public DiffCollector(Visitor visitor, IDiffListener listener)
        {
            _visitor = visitor;
            _listener = listener;
        }

        public Task<IEnumerable<(Commit Commit, TreeEntryChanges Diff)>> Walk(Commit commit)
        {
            return Task.Run(() =>
            {
                _visitor.Visited += _listener.OnCommitVisited;
                try
                {
                    _visitor.Walk(commit);
                    return _listener.Diffs;
                }
                finally
                {
                    _visitor.Visited -= _listener.OnCommitVisited;
                }
            });
        }
    }
}
{'fraction_non_alphanumeric': 0.0747074707470747, 'fraction_numerical': 0.0009000900090009, 'mean_word_length': 1.6183745583038869, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5546094', 'n_tokens_mistral': 566, 'n_tokens_neox': 550, 'n_words': 114}