Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Gill <tyler.gill@byu.net>2021-03-29 08:20:20 +0300
committerTyler Gill <tyler.gill@byu.net>2021-03-29 08:20:20 +0300
commitfa33e5f135b09a3c464a492b21affea51b397a3c (patch)
treea346cad82300da2553cc14f2da23ad1e20a18188
parent3dce0df1064aab6da5db171ac833876583f7946f (diff)
Remove CopyStream buffering logic (will try to make a separate pull request for that)
-rw-r--r--Duplicati/Library/Utility/Utility.cs64
1 files changed, 6 insertions, 58 deletions
diff --git a/Duplicati/Library/Utility/Utility.cs b/Duplicati/Library/Utility/Utility.cs
index 0302d0da4..ae6cc8a75 100644
--- a/Duplicati/Library/Utility/Utility.cs
+++ b/Duplicati/Library/Utility/Utility.cs
@@ -34,15 +34,7 @@ namespace Duplicati.Library.Utility
/// Size of buffers for copying stream
/// </summary>
public static long DEFAULT_BUFFER_SIZE => SystemContextSettings.Buffersize;
-
- /// <summary>
- /// Buffer of the default size which can be reused.
- /// </summary>
- /// <remarks>
- /// This is stored as a weak reference so that it may be reclaimed in low memory.
- /// </remarks>
- private static WeakReference<byte[]> defaultBufferCache = null;
-
+
/// <summary>
/// A cache of the FileSystemCaseSensitive property, which is computed upon the first access.
/// </summary>
@@ -98,13 +90,8 @@ namespace Duplicati.Library.Utility
// ignored
}
- bool returnBuffer = false;
- if (buf == null)
- {
- buf = GetDefaultBuffer();
- returnBuffer = true;
- }
-
+ buf = buf ?? new byte[DEFAULT_BUFFER_SIZE];
+
int read;
long total = 0;
while ((read = source.Read(buf, 0, buf.Length)) != 0)
@@ -112,12 +99,7 @@ namespace Duplicati.Library.Utility
target.Write(buf, 0, read);
total += read;
}
-
- if (returnBuffer)
- {
- ReturnDefaultBuffer(buf);
- }
-
+
return total;
}
@@ -146,12 +128,7 @@ namespace Duplicati.Library.Utility
try { source.Position = 0; }
catch {}
- bool returnBuffer = false;
- if (buf == null)
- {
- buf = GetDefaultBuffer();
- returnBuffer = true;
- }
+ buf = buf ?? new byte[DEFAULT_BUFFER_SIZE];
int read;
long total = 0;
@@ -162,39 +139,10 @@ namespace Duplicati.Library.Utility
await target.WriteAsync(buf, 0, read, cancelToken).ConfigureAwait(false);
total += read;
}
-
- if (returnBuffer)
- {
- ReturnDefaultBuffer(buf);
- }
-
+
return total;
}
- private static byte[] GetDefaultBuffer()
- {
- byte[] buffer = null;
- WeakReference<byte[]> cachedBuffer = Interlocked.Exchange(ref defaultBufferCache, null);
- if (cachedBuffer != null && cachedBuffer.TryGetTarget(out buffer))
- {
- // Clear the buffer only when it is being reused, instead of when it is put in the cache.
- // This prevents doing unnecessary work to clear the buffer in cases where it isn't reused
- // (e.g., when the garbage collector reclaims the buffer before it is needed again.)
- Array.Clear(buffer, 0, buffer.Length);
- }
-
- return buffer ?? new byte[DEFAULT_BUFFER_SIZE];
- }
-
- private static void ReturnDefaultBuffer(byte[] buffer)
- {
- if (buffer.Length == DEFAULT_BUFFER_SIZE)
- {
- Interlocked.Exchange(ref defaultBufferCache, new WeakReference<byte[]>(buffer));
- }
- }
-
-
/// <summary>
/// These are characters that must be escaped when using a globbing expression
/// </summary>