improved performance of CompareFiles function
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3305 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -32,34 +32,36 @@ bool
|
|||||||
CompareStreams(BPositionIO &a, BPositionIO &b)
|
CompareStreams(BPositionIO &a, BPositionIO &b)
|
||||||
{
|
{
|
||||||
off_t alen = 0, blen = 0;
|
off_t alen = 0, blen = 0;
|
||||||
uint8 *abuf = NULL, *bbuf = NULL;
|
const uint32 kbuflen = 2048;
|
||||||
|
uint8 abuf[kbuflen], bbuf[kbuflen];
|
||||||
|
|
||||||
a.Seek(0, SEEK_END);
|
a.Seek(0, SEEK_END);
|
||||||
alen = a.Position();
|
alen = a.Position();
|
||||||
b.Seek(0, SEEK_END);
|
b.Seek(0, SEEK_END);
|
||||||
blen = b.Position();
|
blen = b.Position();
|
||||||
|
|
||||||
if (alen != blen)
|
if (alen != blen)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool bresult = false;
|
if (a.Seek(0, SEEK_SET) != 0)
|
||||||
abuf = new uint8[alen];
|
return false;
|
||||||
bbuf = new uint8[blen];
|
if (b.Seek(0, SEEK_SET) != 0)
|
||||||
if (a.ReadAt(0, abuf, alen) == alen) {
|
return false;
|
||||||
if (b.ReadAt(0, bbuf, blen) == blen) {
|
|
||||||
if (memcmp(abuf, bbuf, alen) == 0)
|
ssize_t read = 0;
|
||||||
bresult = true;
|
while (alen > 0) {
|
||||||
else
|
read = a.Read(abuf, kbuflen);
|
||||||
bresult = false;
|
if (read < 0)
|
||||||
}
|
return false;
|
||||||
|
if (b.Read(bbuf, read) != read)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (memcmp(abuf, bbuf, read) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
alen -= read;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] abuf;
|
return true;
|
||||||
abuf = NULL;
|
|
||||||
delete[] bbuf;
|
|
||||||
bbuf = NULL;
|
|
||||||
|
|
||||||
return bresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check each member of translator_info to see that it matches
|
// Check each member of translator_info to see that it matches
|
||||||
|
|||||||
Reference in New Issue
Block a user