diff --git a/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
similarity index 98%
rename from LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs
rename to LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
index 39ccf1f5b..f2fc14b66 100644
--- a/LibGit2Sharp.Tests/SubstitutionCipherFilterFixture.cs
+++ b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
@@ -6,7 +6,7 @@
namespace LibGit2Sharp.Tests
{
- public class SubstitutionCipherFilterFixture : BaseFixture
+ public class FilterSubstitutionCipherFixture : BaseFixture
{
[Fact]
public void CorrectlyEncodesAndDecodesInput()
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 6f5f64e63..21bf7faba 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -96,7 +96,7 @@
-
+
diff --git a/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs b/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs
index 25a90be4c..184ca526e 100644
--- a/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/SubstitutionCipherFilter.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
-using System.Text;
namespace LibGit2Sharp.Tests.TestHelpers
{
@@ -35,27 +34,23 @@ protected override int Smudge(string path, Stream input, Stream output)
public static int RotateByThirteenPlaces(Stream input, Stream output)
{
+ int value;
- using (var streamReader = new StreamReader(input, Encoding.UTF8))
+ while ((value = input.ReadByte()) != -1)
{
- var inputString = streamReader.ReadToEnd();
- char[] array = inputString.ToCharArray();
- for (int i = 0; i < inputString.Length; i++)
+ if ((value >= 'a' && value <= 'm') || (value >= 'A' && value <= 'M'))
{
- var value = inputString[i];
- if ((value >= 'a' && value <= 'm') || (value >= 'A' && value <= 'M'))
- array[i] = (char)(value + 13);
- else if ((value >= 'n' && value <= 'z') || (value >= 'N' && value <= 'Z'))
- array[i] = (char)(value - 13);
+ value += 13;
}
-
- using (var streamWriter = new StreamWriter(output, Encoding.UTF8))
+ else if ((value >= 'n' && value <= 'z') || (value >= 'N' && value <= 'Z'))
{
- streamWriter.Write(array);
+ value -= 13;
}
- return 0;
+ output.WriteByte((byte)value);
}
+
+ return 0;
}
}
}
diff --git a/LibGit2Sharp/Core/GitBufWriteStream.cs b/LibGit2Sharp/Core/GitBufWriteStream.cs
index f727fec1e..7cc281f22 100644
--- a/LibGit2Sharp/Core/GitBufWriteStream.cs
+++ b/LibGit2Sharp/Core/GitBufWriteStream.cs
@@ -13,7 +13,7 @@ internal GitBufWriteStream(IntPtr gitBufPointer)
this.gitBufPointer = gitBufPointer;
//Preallocate the buffer
- Proxy.git_buf_grow(gitBufPointer, 1024);
+ Proxy.git_buf_grow(gitBufPointer, 4096);
}
public override void Flush()
@@ -37,32 +37,9 @@ public override int Read(byte[] buffer, int offset, int count)
public override void Write(byte[] buffer, int offset, int count)
{
- AutoGrowBuffer(count);
-
Proxy.git_buf_put(gitBufPointer, buffer, offset, count);
}
- private void AutoGrowBuffer(int count)
- {
- var gitBuf = gitBufPointer.MarshalAs();
-
- var ulongCount = Convert.ToUInt64(count);
- var asize = (ulong)gitBuf.asize;
- var size = (ulong)gitBuf.size;
-
- var isBufferLargeEnoughToHoldTheNewData = (asize - size) > ulongCount;
- var filledBufferPercentage = (100.0 * size / asize);
-
- if (isBufferLargeEnoughToHoldTheNewData && filledBufferPercentage < 90)
- {
- return;
- }
-
- var targetSize = (ulong)(1.5 * (asize + ulongCount));
-
- Proxy.git_buf_grow(gitBufPointer, targetSize);
- }
-
public override bool CanRead
{
get { return false; }
diff --git a/LibGit2Sharp/Filter.cs b/LibGit2Sharp/Filter.cs
index 596b8feb0..5697d7d6c 100644
--- a/LibGit2Sharp/Filter.cs
+++ b/LibGit2Sharp/Filter.cs
@@ -237,10 +237,11 @@ int ApplyCallback(GitFilter gitFilter, IntPtr payload,
var filterSource = FilterSource.FromNativePtr(filterSourcePtr);
using (var reader = new GitBufReadStream(gitBufferFromPtr))
using (var writer = new GitBufWriteStream(gitBufferToPtr))
+ using (var bufferedWriter = new BufferedStream(writer))
{
return filterSource.SourceMode == FilterMode.Clean ?
- Clean(filterSource.Path, reader, writer) :
- Smudge(filterSource.Path, reader, writer);
+ Clean(filterSource.Path, reader, bufferedWriter) :
+ Smudge(filterSource.Path, reader, bufferedWriter);
}
}
}