other-licenses/7zstub/src/7zip/Compress/LZ/LZOutWindow.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // LZOutWindow.h
michael@0 2
michael@0 3 #ifndef __LZ_OUT_WINDOW_H
michael@0 4 #define __LZ_OUT_WINDOW_H
michael@0 5
michael@0 6 #include "../../IStream.h"
michael@0 7 #include "../../Common/OutBuffer.h"
michael@0 8
michael@0 9 #ifndef _NO_EXCEPTIONS
michael@0 10 typedef COutBufferException CLZOutWindowException;
michael@0 11 #endif
michael@0 12
michael@0 13 class CLZOutWindow: public COutBuffer
michael@0 14 {
michael@0 15 public:
michael@0 16 void Init(bool solid = false);
michael@0 17
michael@0 18 // distance >= 0, len > 0,
michael@0 19 bool CopyBlock(UInt32 distance, UInt32 len)
michael@0 20 {
michael@0 21 UInt32 pos = _pos - distance - 1;
michael@0 22 if (distance >= _pos)
michael@0 23 {
michael@0 24 if (!_overDict || distance >= _bufferSize)
michael@0 25 return false;
michael@0 26 pos += _bufferSize;
michael@0 27 }
michael@0 28 do
michael@0 29 {
michael@0 30 if (pos == _bufferSize)
michael@0 31 pos = 0;
michael@0 32 _buffer[_pos++] = _buffer[pos++];
michael@0 33 if (_pos == _limitPos)
michael@0 34 FlushWithCheck();
michael@0 35 }
michael@0 36 while(--len != 0);
michael@0 37 return true;
michael@0 38 }
michael@0 39
michael@0 40 void PutByte(Byte b)
michael@0 41 {
michael@0 42 _buffer[_pos++] = b;
michael@0 43 if (_pos == _limitPos)
michael@0 44 FlushWithCheck();
michael@0 45 }
michael@0 46
michael@0 47 Byte GetByte(UInt32 distance) const
michael@0 48 {
michael@0 49 UInt32 pos = _pos - distance - 1;
michael@0 50 if (pos >= _bufferSize)
michael@0 51 pos += _bufferSize;
michael@0 52 return _buffer[pos];
michael@0 53 }
michael@0 54 };
michael@0 55
michael@0 56 #endif

mercurial