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:
Matthew Wilber 2003-05-24 23:03:40 +00:00
parent 9edca8f79e
commit f3aa49b1b1

View File

@ -32,34 +32,36 @@ bool
CompareStreams(BPositionIO &a, BPositionIO &b)
{
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);
alen = a.Position();
b.Seek(0, SEEK_END);
blen = b.Position();
blen = b.Position();
if (alen != blen)
return false;
bool bresult = false;
abuf = new uint8[alen];
bbuf = new uint8[blen];
if (a.ReadAt(0, abuf, alen) == alen) {
if (b.ReadAt(0, bbuf, blen) == blen) {
if (memcmp(abuf, bbuf, alen) == 0)
bresult = true;
else
bresult = false;
}
}
delete[] abuf;
abuf = NULL;
delete[] bbuf;
bbuf = NULL;
if (a.Seek(0, SEEK_SET) != 0)
return false;
if (b.Seek(0, SEEK_SET) != 0)
return false;
ssize_t read = 0;
while (alen > 0) {
read = a.Read(abuf, kbuflen);
if (read < 0)
return false;
if (b.Read(bbuf, read) != read)
return false;
if (memcmp(abuf, bbuf, read) != 0)
return false;
alen -= read;
}
return bresult;
return true;
}
// Check each member of translator_info to see that it matches