other-licenses/7zstub/src/7zip/Archive/Common/CoderMixer2.cpp

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 // CoderMixer2.cpp
michael@0 2
michael@0 3 #include "StdAfx.h"
michael@0 4
michael@0 5 #include "CoderMixer2.h"
michael@0 6
michael@0 7 namespace NCoderMixer2 {
michael@0 8
michael@0 9 CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):
michael@0 10 _srcBindInfo(srcBindInfo)
michael@0 11 {
michael@0 12 srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);
michael@0 13
michael@0 14 UInt32 j;
michael@0 15 for (j = 0; j < NumSrcInStreams; j++)
michael@0 16 {
michael@0 17 _srcInToDestOutMap.Add(0);
michael@0 18 DestOutToSrcInMap.Add(0);
michael@0 19 }
michael@0 20 for (j = 0; j < _numSrcOutStreams; j++)
michael@0 21 {
michael@0 22 _srcOutToDestInMap.Add(0);
michael@0 23 _destInToSrcOutMap.Add(0);
michael@0 24 }
michael@0 25
michael@0 26 UInt32 destInOffset = 0;
michael@0 27 UInt32 destOutOffset = 0;
michael@0 28 UInt32 srcInOffset = NumSrcInStreams;
michael@0 29 UInt32 srcOutOffset = _numSrcOutStreams;
michael@0 30
michael@0 31 for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)
michael@0 32 {
michael@0 33 const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];
michael@0 34
michael@0 35 srcInOffset -= srcCoderInfo.NumInStreams;
michael@0 36 srcOutOffset -= srcCoderInfo.NumOutStreams;
michael@0 37
michael@0 38 UInt32 j;
michael@0 39 for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)
michael@0 40 {
michael@0 41 UInt32 index = srcInOffset + j;
michael@0 42 _srcInToDestOutMap[index] = destOutOffset;
michael@0 43 DestOutToSrcInMap[destOutOffset] = index;
michael@0 44 }
michael@0 45 for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)
michael@0 46 {
michael@0 47 UInt32 index = srcOutOffset + j;
michael@0 48 _srcOutToDestInMap[index] = destInOffset;
michael@0 49 _destInToSrcOutMap[destInOffset] = index;
michael@0 50 }
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)
michael@0 55 {
michael@0 56 destBindInfo.Coders.Clear();
michael@0 57 destBindInfo.BindPairs.Clear();
michael@0 58 destBindInfo.InStreams.Clear();
michael@0 59 destBindInfo.OutStreams.Clear();
michael@0 60
michael@0 61 int i;
michael@0 62 for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)
michael@0 63 {
michael@0 64 const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];
michael@0 65 CCoderStreamsInfo destCoderInfo;
michael@0 66 destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;
michael@0 67 destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;
michael@0 68 destBindInfo.Coders.Add(destCoderInfo);
michael@0 69 }
michael@0 70 for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)
michael@0 71 {
michael@0 72 const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];
michael@0 73 CBindPair destBindPair;
michael@0 74 destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];
michael@0 75 destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];
michael@0 76 destBindInfo.BindPairs.Add(destBindPair);
michael@0 77 }
michael@0 78 for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)
michael@0 79 destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);
michael@0 80 for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)
michael@0 81 destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);
michael@0 82 }
michael@0 83
michael@0 84 CCoderInfo::CCoderInfo(UInt32 numInStreams, UInt32 numOutStreams):
michael@0 85 NumInStreams(numInStreams),
michael@0 86 NumOutStreams(numOutStreams)
michael@0 87 {
michael@0 88 InSizes.Reserve(NumInStreams);
michael@0 89 InSizePointers.Reserve(NumInStreams);
michael@0 90 OutSizePointers.Reserve(NumOutStreams);
michael@0 91 OutSizePointers.Reserve(NumOutStreams);
michael@0 92 }
michael@0 93
michael@0 94 static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,
michael@0 95 CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)
michael@0 96 {
michael@0 97 sizes.Clear();
michael@0 98 sizePointers.Clear();
michael@0 99 for(UInt32 i = 0; i < numItems; i++)
michael@0 100 {
michael@0 101 if (srcSizes == 0 || srcSizes[i] == NULL)
michael@0 102 {
michael@0 103 sizes.Add(0);
michael@0 104 sizePointers.Add(NULL);
michael@0 105 }
michael@0 106 else
michael@0 107 {
michael@0 108 sizes.Add(*srcSizes[i]);
michael@0 109 sizePointers.Add(&sizes.Back());
michael@0 110 }
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 void CCoderInfo::SetCoderInfo(const UInt64 **inSizes,
michael@0 115 const UInt64 **outSizes)
michael@0 116 {
michael@0 117 SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
michael@0 118 SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
michael@0 119 }
michael@0 120
michael@0 121 }

mercurial