Skip to content

Commit 1847274

Browse files
deciphererpiksel
authored andcommitted
Merge PR #301: Revert ArraySegment simplification to speed up CRC32 calculation
1 parent 408916b commit 1847274

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/ICSharpCode.SharpZipLib/Checksum/BZip2Crc.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ public void Update(byte[] buffer)
177177
/// </param>
178178
public void Update(ArraySegment<byte> segment)
179179
{
180-
foreach (byte b in segment)
181-
{
182-
Update(b);
183-
}
180+
var count = segment.Count;
181+
var offset = segment.Offset;
182+
183+
while (--count >= 0)
184+
Update(segment.Array[offset++]);
184185
}
185186
}
186187
}

src/ICSharpCode.SharpZipLib/Checksum/Crc32.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ public void Update(byte[] buffer)
166166
/// </param>
167167
public void Update(ArraySegment<byte> segment)
168168
{
169-
foreach (byte b in segment)
170-
{
171-
Update(b);
172-
}
169+
var count = segment.Count;
170+
var offset = segment.Offset;
171+
172+
while (--count >= 0)
173+
Update(segment.Array[offset++]);
173174
}
174175
}
175176
}

0 commit comments

Comments
 (0)