]> git.cworth.org Git - apitrace/commitdiff
Merge remote-tracking branch 'origin/master' into on-demand-loading
authorZack Rusin <zack@kde.org>
Thu, 1 Sep 2011 04:01:02 +0000 (00:01 -0400)
committerZack Rusin <zack@kde.org>
Thu, 1 Sep 2011 04:01:02 +0000 (00:01 -0400)
1  2 
trace_snappyfile.cpp

diff --combined trace_snappyfile.cpp
index c13a97940d04c0e0372d42124f8ba2fddafc0723,5804c3bbb2dc76f9e731554329745ee56b7b53de..07a62f6bcc187edb38875a43122abfee2c3ddc7d
@@@ -28,8 -28,6 +28,8 @@@
  
  #include <snappy.h>
  
 +#include <iostream>
 +
  #include <assert.h>
  #include <string.h>
  
@@@ -68,7 -66,9 +68,9 @@@ SnappyFile::SnappyFile(const std::strin
        m_cachePtr(0),
        m_cacheSize(0)
  {
-     m_compressedCache = new char[SNAPPY_CHUNK_SIZE];
+     size_t maxCompressedLength =
+         snappy::MaxCompressedLength(SNAPPY_CHUNK_SIZE);
+     m_compressedCache = new char[maxCompressedLength];
  }
  
  SnappyFile::~SnappyFile()
@@@ -201,7 -201,6 +203,7 @@@ void SnappyFile::flushCache(
          if (m_stream.eof())
              return;
          //assert(m_cachePtr == m_cache + m_cacheSize);
 +        m_currentOffset.chunk = m_stream.tellg();
          size_t compressedLength;
          compressedLength = readCompressedLength();
          m_stream.read((char*)m_compressedCache, compressedLength);
@@@ -241,28 -240,3 +243,28 @@@ uint32_t SnappyFile::readCompressedLeng
      m_stream.read((char*)&len, sizeof len);
      return len;
  }
 +
 +bool SnappyFile::supportsOffsets() const
 +{
 +    return true;
 +}
 +
 +File::Offset SnappyFile::currentOffset()
 +{
 +    m_currentOffset.offsetInChunk = m_cachePtr - m_cache;
 +    return m_currentOffset;
 +}
 +
 +void SnappyFile::setCurrentOffset(const File::Offset &offset)
 +{
 +    // to remove eof bit
 +    m_stream.clear();
 +    // seek to the start of a chunk
 +    m_stream.seekg(offset.chunk, std::ios::beg);
 +    // load the chunk
 +    flushCache();
 +    assert(m_cacheSize >= offset.offsetInChunk);
 +    // seek within our cache to the correct location within the chunk
 +    m_cachePtr = m_cache + offset.offsetInChunk;
 +
 +}