mirror of https://github.com/libAthena/athena.git
* Fix commit
* Fix LZO implementation (use lzo1x_decompress_safe)
This commit is contained in:
parent
c28cfbaba6
commit
190f1e8c17
|
@ -10,7 +10,7 @@ namespace io
|
|||
class IStreamReader : public IStream
|
||||
{
|
||||
public:
|
||||
virtual ~IStreamReader();
|
||||
virtual ~IStreamReader() {}
|
||||
virtual void setEndian(Endian) = 0;
|
||||
virtual Endian endian() const= 0;
|
||||
virtual bool isBigEndian() const= 0;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace io
|
|||
class IStreamWriter : public IStream
|
||||
{
|
||||
public:
|
||||
virtual ~IStreamWriter();
|
||||
virtual ~IStreamWriter() {}
|
||||
virtual void setEndian(Endian) = 0;
|
||||
virtual Endian endian() const= 0;
|
||||
virtual bool isBigEndian() const= 0;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef MEMORYWRITER_HPP
|
||||
#define MEMORYWRITER_HPP
|
||||
|
||||
#include "Athena/IStream.hpp"
|
||||
#include "Athena/IStreamWriter.hpp"
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace io
|
|||
* this allows for fast, flexible code as well as the ability to quickly modify data
|
||||
* \sa Stream
|
||||
*/
|
||||
class MemoryWriter : public IStream
|
||||
class MemoryWriter : public IStreamWriter
|
||||
{
|
||||
public:
|
||||
/*! \brief This constructor takes an existing buffer to write to.
|
||||
|
|
|
@ -109,7 +109,7 @@ atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8*
|
|||
{
|
||||
int srcSize = sourceSize;
|
||||
int size = dstSize;
|
||||
int result = lzo1x_decompress(source, srcSize, dst, (lzo_uintp)&size, NULL);
|
||||
int result = lzo1x_decompress_safe(source, srcSize, dst, (lzo_uintp)&size, NULL);
|
||||
dstSize -= size;
|
||||
|
||||
return result;
|
||||
|
|
|
@ -13,15 +13,15 @@ LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt3
|
|||
{
|
||||
if(minimumMatch > 0 )
|
||||
m_minimumMatch = minimumMatch;
|
||||
else
|
||||
else
|
||||
m_minimumMatch = 3;
|
||||
if(slidingWindow > 0)
|
||||
m_slidingWindow = slidingWindow;
|
||||
else
|
||||
else
|
||||
m_slidingWindow = 4096;
|
||||
if(lookAheadWindow > 0)
|
||||
m_lookAheadWindow = lookAheadWindow;
|
||||
else
|
||||
else
|
||||
m_lookAheadWindow = 18;
|
||||
m_buffer.reserve(m_minimumMatch);
|
||||
}
|
||||
|
@ -33,80 +33,80 @@ void LZLookupTable::setLookAheadWindow(atInt32 lookAheadWindow)
|
|||
{
|
||||
if(lookAheadWindow > 0)
|
||||
m_lookAheadWindow = lookAheadWindow;
|
||||
else
|
||||
else
|
||||
m_lookAheadWindow = 18;
|
||||
}
|
||||
|
||||
LZLengthOffset LZLookupTable::search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd)
|
||||
{
|
||||
LZLengthOffset loPair = {0,0};
|
||||
//Returns negative 1 for search failures since the current position is passed the size to be compressed
|
||||
//Returns negative 1 for search failures since the current position is passed the size to be compressed
|
||||
if(curPos >=dataEnd)
|
||||
{
|
||||
{
|
||||
loPair.length=-1;
|
||||
return loPair;
|
||||
}
|
||||
}
|
||||
std::copy(curPos, curPos + m_minimumMatch, m_buffer.begin());
|
||||
int32_t currentOffset = static_cast<atInt32>(curPos - dataBegin);
|
||||
//Find code
|
||||
//Find code
|
||||
if(currentOffset > 0 && (dataEnd - curPos) >= m_minimumMatch)
|
||||
{
|
||||
{
|
||||
auto elements = table.equal_range(m_buffer);
|
||||
elements.second--;
|
||||
elements.first--;
|
||||
//Iterate over keys in reverse order. C++11 guarantees that the relative order of elements is maintained for the same key
|
||||
for(auto iter = elements.second; iter != elements.first; iter--)
|
||||
{
|
||||
elements.second--;
|
||||
elements.first--;
|
||||
//Iterate over keys in reverse order. C++11 guarantees that the relative order of elements is maintained for the same key
|
||||
for(auto iter = elements.second; iter != elements.first; iter--)
|
||||
{
|
||||
int32_t matchLength = m_minimumMatch;
|
||||
int32_t lookAheadBufferLength = ((dataEnd - curPos) < m_lookAheadWindow) ? static_cast<int32_t>(dataEnd - curPos) : m_lookAheadWindow;
|
||||
for(; matchLength < lookAheadBufferLength; ++matchLength)
|
||||
{
|
||||
for(; matchLength < lookAheadBufferLength; ++matchLength)
|
||||
{
|
||||
if(*(dataBegin + iter->second + matchLength) != *(curPos + matchLength))
|
||||
break;
|
||||
}
|
||||
//Store the longest match found so far into length_offset struct.
|
||||
//When lengths are the same the closer offset to the lookahead buffer wins
|
||||
break;
|
||||
}
|
||||
//Store the longest match found so far into length_offset struct.
|
||||
//When lengths are the same the closer offset to the lookahead buffer wins
|
||||
if(loPair.length < (atUint32)matchLength)
|
||||
{
|
||||
{
|
||||
loPair.length = matchLength;
|
||||
loPair.offset = currentOffset - iter->second;
|
||||
}
|
||||
//Found the longest match so break out of loop
|
||||
}
|
||||
//Found the longest match so break out of loop
|
||||
if(loPair.length == (atUint32)m_lookAheadWindow)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//end find code
|
||||
//Insert code
|
||||
break;
|
||||
}
|
||||
}
|
||||
//end find code
|
||||
//Insert code
|
||||
table.insert(std::make_pair(m_buffer, currentOffset));
|
||||
for(atUint32 i = 1; i < loPair.length; i++)
|
||||
{
|
||||
{
|
||||
if(dataEnd - (curPos + i) < m_minimumMatch)
|
||||
break;
|
||||
break;
|
||||
std::copy(curPos + i, curPos + m_minimumMatch + i, m_buffer.begin());
|
||||
table.insert(std::make_pair(m_buffer, currentOffset + i));
|
||||
|
||||
}
|
||||
//end insert code
|
||||
//Delete code
|
||||
|
||||
}
|
||||
//end insert code
|
||||
//Delete code
|
||||
int32_t slidingWindowOffset = std::max(0, currentOffset - m_slidingWindow);//Absolute offset
|
||||
int32_t tablesize=static_cast<int32_t>(table.size());
|
||||
int32_t tablesize=static_cast<int32_t>(table.size());
|
||||
for(int32_t i = 0; i < tablesize - m_slidingWindow; ++i)
|
||||
{
|
||||
{
|
||||
std::copy(dataBegin + slidingWindowOffset + i, dataBegin + slidingWindowOffset + m_minimumMatch + i, m_buffer.begin());
|
||||
auto elements = table.equal_range(m_buffer);
|
||||
for(auto iter = elements.first; iter != elements.second; iter++)
|
||||
{
|
||||
if(slidingWindowOffset + i == iter->second)
|
||||
{
|
||||
table.erase(iter);
|
||||
//There should no occurance of the map with the same value
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//end delete code
|
||||
for(auto iter = elements.first; iter != elements.second; iter++)
|
||||
{
|
||||
if(slidingWindowOffset + i == iter->second)
|
||||
{
|
||||
table.erase(iter);
|
||||
//There should no occurance of the map with the same value
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//end delete code
|
||||
return loPair;
|
||||
//break lookupTable.cpp:109 if table.size()> 4096
|
||||
//break lookupTable.cpp:109 if table.size()> 4096
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue