134 */ |
133 */ |
135 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks) |
134 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks) |
136 { |
135 { |
137 #if __GNUC__ >= 4 |
136 #if __GNUC__ >= 4 |
138 // Try to detect if the class' layout has changed. |
137 // Try to detect if the class' layout has changed. |
139 COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 ); |
138 COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 ); |
140 COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 ); |
139 COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 ); |
141 COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) ); |
140 COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) ); |
142 |
141 |
143 // Compute the size of the class, including rounding it up to a multiple of 4 |
142 // Compute the size of the class, including rounding it up to a multiple of 4 |
144 // bytes. |
143 // bytes. |
145 |
144 unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance); |
146 unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance); |
145 while (n & 0x1f) |
147 |
146 { |
148 while (n & 0x1f) |
147 n++; |
149 { |
148 } |
150 n++; |
|
151 } |
|
152 // Allocate the raw memory ... |
149 // Allocate the raw memory ... |
153 void* p = ::operator new(n); |
150 void* p = ::operator new(n); |
154 // ... And create the object in that memory. |
151 // ... And create the object in that memory. |
155 return new(p) HDeflateHash; |
152 return new(p) HDeflateHash; |
156 #else |
153 #else |
157 return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash; |
154 return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash; |
158 #endif |
155 #endif |
159 } |
156 } |
160 |
157 |