~ubuntu-branches/ubuntu/utopic/unrar-nonfree/utopic-updates

« back to all changes in this revision

Viewing changes to suballoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Meredith
  • Date: 2006-11-01 11:58:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061101115820-41wn9un5v4m9r3jh
Tags: 1:3.6.8-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
}
39
39
 
40
40
 
 
41
/*
 
42
   calculate RAR_MEM_BLK + Items address. Real RAR_MEM_BLK size must be
 
43
   equal to UNIT_SIZE, so we cannot just add Items to RAR_MEM_BLK address
 
44
*/
 
45
inline RAR_MEM_BLK* SubAllocator::MBPtr(RAR_MEM_BLK *BasePtr,int Items)
 
46
{
 
47
  return((RAR_MEM_BLK*)( ((byte *)(BasePtr))+U2B(Items) ));
 
48
}
 
49
 
 
50
 
41
51
inline void SubAllocator::SplitBlock(void* pv,int OldIndx,int NewIndx)
42
52
{
43
53
  int i, UDiff=Indx2Units[OldIndx]-Indx2Units[NewIndx];
71
81
    return TRUE;
72
82
  StopSubAllocator();
73
83
  uint AllocSize=t/FIXED_UNIT_SIZE*UNIT_SIZE+UNIT_SIZE;
 
84
#ifdef STRICT_ALIGNMENT_REQUIRED
 
85
  AllocSize+=UNIT_SIZE;
 
86
#endif
74
87
  if ((HeapStart=(byte *)rarmalloc(AllocSize)) == NULL)
75
88
  {
76
89
    ErrHandler.MemoryError();
91
104
  uint RealSize2=Size2/FIXED_UNIT_SIZE*UNIT_SIZE;
92
105
  uint Size1=SubAllocatorSize-Size2;
93
106
  uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+Size1%FIXED_UNIT_SIZE;
 
107
#ifdef STRICT_ALIGNMENT_REQUIRED
 
108
  if (Size1%FIXED_UNIT_SIZE!=0)
 
109
    RealSize1+=UNIT_SIZE-Size1%FIXED_UNIT_SIZE;
 
110
#endif
94
111
  HiUnit=HeapStart+SubAllocatorSize;
95
112
  LoUnit=UnitsStart=HeapStart+RealSize1;
96
113
  FakeUnitsStart=HeapStart+Size1;
126
143
      p->NU=Indx2Units[i];
127
144
    }
128
145
  for (p=s0.next;p != &s0;p=p->next)
129
 
    while ((p1=p+p->NU)->Stamp == 0xFFFF && int(p->NU)+p1->NU < 0x10000)
 
146
    while ((p1=MBPtr(p,p->NU))->Stamp == 0xFFFF && int(p->NU)+p1->NU < 0x10000)
130
147
    {
131
148
      p1->remove();
132
149
      p->NU += p1->NU;
133
150
    }
134
151
  while ((p=s0.next) != &s0)
135
152
  {
136
 
    for (p->remove(), sz=p->NU;sz > 128;sz -= 128, p += 128)
 
153
    for (p->remove(), sz=p->NU;sz > 128;sz -= 128, p=MBPtr(p,128))
137
154
      InsertNode(p,N_INDEXES-1);
138
155
    if (Indx2Units[i=Units2Indx[sz-1]] != sz)
139
156
    {
140
157
      k=sz-Indx2Units[--i];
141
 
      InsertNode(p+(sz-k),k-1);
 
158
      InsertNode(MBPtr(p,sz-k),k-1);
142
159
    }
143
160
    InsertNode(p,i);
144
161
  }
160
177
    {
161
178
      GlueCount--;
162
179
      i=U2B(Indx2Units[indx]);
163
 
      int j=12*Indx2Units[indx];
 
180
      int j=FIXED_UNIT_SIZE*Indx2Units[indx];
164
181
      if (FakeUnitsStart-pText > j)
165
182
      {
166
183
        FakeUnitsStart-=j;