mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
(ArPkStream.Read): optimized with BinarySearch.
This commit is contained in:
parent
13da37b2d9
commit
482e679e58
@ -94,10 +94,16 @@ namespace GameRes.Formats.PalmTree
|
|||||||
this.Position = pos;
|
this.Position = pos;
|
||||||
}
|
}
|
||||||
count = BaseStream.Read (buffer, offset, count);
|
count = BaseStream.Read (buffer, offset, count);
|
||||||
|
if (0 == count)
|
||||||
|
return count;
|
||||||
long buf_pos = pos;
|
long buf_pos = pos;
|
||||||
long buf_end = buf_pos + count;
|
long buf_end = buf_pos + count;
|
||||||
foreach (long ar_pos in m_ar_blocks)
|
int index = m_ar_blocks.BinarySearch (buf_pos-1);
|
||||||
|
if (index < 0)
|
||||||
|
index = ~index;
|
||||||
|
for (; index < m_ar_blocks.Count; ++index)
|
||||||
{
|
{
|
||||||
|
var ar_pos = m_ar_blocks[index];
|
||||||
if (buf_end <= ar_pos)
|
if (buf_end <= ar_pos)
|
||||||
break;
|
break;
|
||||||
if (buf_pos >= ar_pos+2)
|
if (buf_pos >= ar_pos+2)
|
||||||
@ -105,8 +111,9 @@ namespace GameRes.Formats.PalmTree
|
|||||||
int signature_pos = (int)(ar_pos - pos);
|
int signature_pos = (int)(ar_pos - pos);
|
||||||
if (signature_pos >= 0)
|
if (signature_pos >= 0)
|
||||||
buffer[offset+signature_pos] = (byte)'P';
|
buffer[offset+signature_pos] = (byte)'P';
|
||||||
if (signature_pos + 1 >= 0)
|
++signature_pos;
|
||||||
buffer[offset+signature_pos+1] = (byte)'K';
|
if (signature_pos >= 0 && signature_pos < count)
|
||||||
|
buffer[offset+signature_pos] = (byte)'K';
|
||||||
buf_pos = ar_pos + 2;
|
buf_pos = ar_pos + 2;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user